|
|
| Just another Perl shrine | |
| PerlMonks |
Fork + Memoryby exussum0 (Vicar) |
| on Dec 29, 2003 at 22:28 UTC ( [id://317616]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
Some advice on understanding processes beign spawned (should you be using fork)
Use fork and modify as little as you can.
Short explanation...(stolen from here)
Long explanation
For instance, if you have a 20 meg process and spawned off 40 other ones, and each fork modified say, 8 bytes of memory each, then those 8 bytes and whatever blocks that they contain may be copied for each fork. Since the rest of the data/code should be the same between the 41 processes, then you still have those 20 megs all sharing the same piece. Minimally, you'd have a 20 meg process and 40 copies of 8 byte blocks unique to each fork. That's still close to 20 megs. Some older systems do NOT support this "advanced technology" and as soon as you fork, they all get new copies of the process, turning a 20 meg process which forks 40 times go from 20 megs total consumption to 20 + (40*20) megs of consumption. 820megs. Threads are different of course, since two threads can modify the same variable/data without causing a copy. Causing a unique copy if they both wrote to the same data would defeat the point of the thread concept, since they are supposed to share the same data anway, right? Right. UPDATE.. Prior paragraph is wrong. In the perl 5.8.x iThreads do a full copy-on-write, as the replier showed in a thread. ew.
Why it is important to perl
So don't do ... But do this.. You'll save a lot of memory doing things this way... Update: Took out use statements Play that funky music white boy..
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||