Welcome to the Monastery | |
PerlMonks |
Re: Possibly silly perl memory allocation question, duplicating scalarsby BrowserUk (Patriarch) |
on Dec 14, 2004 at 23:59 UTC ( [id://414903]=note: print w/replies, xml ) | Need Help?? |
As the others have identified, x creates the scalars nice and efficiently, and then throws that away by copying it into the scalar, rather than pointing the scalar at the string it created :( If you're on a version of Perl that supports memory files, here's a technique I use for allocating big strings. It's more efficent than x in two ways:
Of course, the latter may be a downside too.
Of course, then you face the problem of using it without it getting freed and replaced, but that's what substr and lvalue refs are for :) Examine what is said, not who speaks.
The end of an era!
"But you should never overestimate the ingenuity of the sceptics to come up with a counter-argument." -Myles Allen"Think for yourself!" - Abigail "Time is a poor substitute for thought"--theorbtwo "Efficiency is intelligent laziness." -David Dunham "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
In Section
Seekers of Perl Wisdom
|
|