Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: What is PERL_COPY_ON_WRITE Compile Option About

by BrowserUk (Patriarch)
on Mar 04, 2005 at 18:18 UTC ( [id://436695]=note: print w/replies, xml ) Need Help??


in reply to What is PERL_COPY_ON_WRITE Compile Option About

PERL_COPY_ON_WRITE has nothing to do with threads or process as far as I can see.

It is used by code within the pp_hot.c, regcomp.h and other places to avoid copying data until (and unless) it is written to.

An example with informative comment comes from pp_hot.c:

#ifdef PERL_COPY_ON_WRITE /* The match may make the string COW. If so, brilliant, because that's just saved us one malloc, copy and free - the regexp has donated the old buffer, and we malloc an entirely new one, rather than the regexp malloc()ing a buffer and copying our original, only for us to throw it away here during the substitution. */ if (SvIsCOW(TARG)) { sv_force_normal_flags(TARG, SV_COW_DROP_PV); } else #endif

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

Replies are listed 'Best First'.
Re^2: What is PERL_COPY_ON_WRITE Compile Option About
by DeadPoet (Scribe) on Mar 04, 2005 at 18:31 UTC
    To All:

    Here is what I just found at
      http://yapc.mongueurs.net/yapc/talk/?tid=85
    "Currently in perl when you write $a = $b, the contents of $b are immediately copied into $a. In theory perl could just pretend that it did the copy, and only actually do it if one of $a or $b is modified. If $b is a large string, and $a is never modified this could potentially be a big efficiency gain. This talk consists of simple pictures - how I didn't do it, and how I did."


    DeadPoet

      It appears that currently, COW is only used for certain copy operations--some of those in the regex engine, shared hash keys (or values?), and a few other places--but not currently simple scalars.

      It looks like the proposal is to extend it's reach.


      Examine what is said, not who speaks.
      Silence betokens consent.
      Love the truth but pardon error.
      That was an excelent talk. Highly informative and imaginatively illustrated with several people holding up cards in a carefully choreographed sequence.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://436695]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 14:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found