In some cases, using substr
or vec
to simulate arrays can be highly beneficial. For example, an array of a thousand booleans will take at least 20,000 bytes of space, but it can be turned into one 125-byte bit vector for a considerable memory savings. The standard Tie::SubstrHash module can also help for certain types of data structure. If you're working with specialist data structures (matrices, for instance) modules that implement these in
C may use less memory than equivalent Perl modules.
Another thing to try is learning whether your Perl was compiled with the
system malloc or with Perl's built-in malloc. Whichever one it is, try
using the other one and see whether this makes a difference. Information
about malloc is in the INSTALL file in the source distribution. You can find out whether you are using
perl's malloc by typing perl -V:usemymalloc
.