What are some good tips for keeping memory usage low in a Perl script? I am interested in learning how to keep my memory footprint as low as possible for systems depending on Perl programs. I know Perl isn't great when it comes to memory usage, but I'd like to know if there are any tips for improving it.
So, what can you do to keep a Perl script using less memory. I'm interested in any suggestions, whether they are actual tips for writing code, or tips for how to compile Perl differently.
Edit for Bounty: I have a perl program that serves as a server for a network application. Each client that connects to it gets it's own child process currently. I've used threads instead of forks as well, but I haven't been able to determine if using threads instead of forks is actually more memory efficient.
I'd like to try using threads instead of forks again. I believe in theory it should save on memory usage. I have a few questions in that regard:
- Do threads created in Perl prevent copying Perl module libraries into memory for each thread?
- Is threads (use threads) the most efficient way (or the only) way to create threads in Perl?
- In threads, I can specify a stack_size paramater, what specifically should I consider when specifying this value, and how does it impact memory usage?
With threads in Perl/Linux, what is the most reliable method to determine the actual memory usage on a per-thread basis?