Search Perl pages
Professions, Sciences, Humanities, Business, ...
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...
Conversions, tests, processing, manipulation,...
Integer, Floating point, Matrix, Statistics, Boolean, ...
Algorithms, Memory, Process control, Debugging, ...
Data storage, Integrity, Encryption, Compression, ...
Networks, protocols, Interprocess, Remote, Client Server, ...
Timing, Calendar and Clock, Audio, Video, Printer, Controls...
Management, Filtering, File & Directory access, Viewers, ...
Next: Miscellaneous efficiency enhancements
If perl is compiled with the malloc included with the perl distribution
(that is, if |
perl -V:d_mymalloc is 'define') then you can print memory statistics at runtime by running
env PERL_DEBUG_MSTATS=2 perl your_script_here
The value of 2 means to print statistics after compilation and on exit;
with a value of 1, the statistics are printed only on exit. (If you want
the statistics at an arbitrary time, you'll need to install the optional
Three new compilation flags are recognized by malloc.c. (They have no
effect if perl is compiled with system
If this macro is defined, running out of memory need not be a fatal error:
a memory pool can allocated by assigning to the special variable
$^M. See $^M.
Perl memory allocation is by bucket with sizes close to powers of two.
Because of these malloc overhead may be big, especially for data of size
exactly a power of two. If
PACK_MALLOC is defined, perl uses a slightly different algorithm for small allocations
(up to 64 bytes long), which makes it possible to have overhead down to 1
byte for allocations which are powers of two (and appear quite often).
Expected memory savings (with 8-byte alignment in
alignbytes) is about 20% for typical Perl usage. Expected slowdown due to additional
malloc overhead is in fractions of a percent (hard to measure, because of
the effect of saved memory on speed).
PACK_MALLOC, this macro improves allocations of data with size close to a power of two; but this works for big allocations (starting with
16K by default). Such allocations are typical for big hashes and special-purpose scripts, especially image processing.
On recent systems, the fact that perl requires
2M from system for
1M allocation will not affect speed of execution, since the tail of such a chunk is not going to be touched (and thus will not require real memory). However, it may result in a premature out-of-memory error. So if you will be manipulating very large blocks with sizes close to powers of two, it would be wise to define this macro.
Expected saving of memory is 0-100% (100% in applications which require
most memory in such 2**n chunks); expected slowdown is negligible.
Source: what's new for perl5.004
Copyright: Larry Wall, et al.
Previous: DESTROY this
(Corrections, notes, and links courtesy of RocketAware.com)
Up to: Memory blocks (Sometimes called "Byte Strings")
Search | About | Comments | Submit Path: RocketAware > Perl >
RocketAware.com is a service of Mib Software
Copyright 2000, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments