Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Does Perl have a baked-in memory llimit?

by dave_the_m (Monsignor)
on Nov 11, 2023 at 21:31 UTC ( [id://11155563] : note . print w/replies, xml ) Need Help??


in reply to Does Perl have a baked-in memory llimit?

Have you experimented with the buf_ref, scalar_ref and blk_size options to File::Slurp's read_file() method? In particular, with the default settings read_file() will keep reading 1Mb blocks from the file and appending it to a local variable. Each append may cause perl to reallocate the buffer used for the string, and depending on your OS's malloc() library, you may end up with allocated but not reused 1Mb, 2Mb, 3Mb, etc buffers. Try setting blk_size to the size of the file (possibly rounded up to a power of 2).

When read_file() returns the string, the return value gets copied (possibly twice). Perl these days is fairly good at sharing or stealing buffers when copying strings, but buf_ref or scalar_ref may still help, depending on the circumstances and your perl version.

Dave.

  • Comment on Re: Does Perl have a baked-in memory llimit?