diotalevi has asked for the wisdom of the Perl Monks concerning the following question:
I'm appending to a string four bytes a time. Almost everything is 2**19 bytes long or shorter. I'd like to pre-grow my string so perl doesn't have to reallocate it each time I grow the string larger than 2**10 .. 2**18. I can never seem to remember the trick for this so I'm penning it as a SoPW. Help me Obi-wan, you're my only hope.
grow( my( $str ), 2**19 ); while ( ... ) { $str .= pack 'J', ...; # append four bytes at a time. }
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Pre-grow a string
by BrowserUk (Patriarch) on Aug 02, 2007 at 17:24 UTC | |
Re: Pre-grow a string (MTOW)
by tye (Sage) on Aug 02, 2007 at 16:59 UTC | |
by almut (Canon) on Aug 02, 2007 at 17:36 UTC | |
by tye (Sage) on Aug 02, 2007 at 17:45 UTC | |
Re: Pre-grow a string
by ikegami (Patriarch) on Aug 02, 2007 at 16:50 UTC | |
Re: Pre-grow a string
by whereiskurt (Friar) on Aug 02, 2007 at 16:56 UTC | |
Re: Pre-grow a string
by ysth (Canon) on Aug 03, 2007 at 00:22 UTC | |
Re: Pre-grow a string
by krishnoid (Novice) on Aug 02, 2007 at 23:04 UTC |