http://qs321.pair.com?node_id=653105


in reply to RFC: Abusing "virtual" memory

this application blossomed to about 44 megabytes, which caused about 75,000 page faults

Simple solution. Pre-expand. If it's an array, $#array = nnnn;. If it's a hash, keys %hash = nnnn;.

It's not a complete solution as it only reserves space for the structure, not for the scalars held by the structure, but there is a solution to that also.

Allocate and free a larger scalar, my $space = 'x' x 44e6;. This will cause the application to request and commit the total memory requirement from the OS in one big hit. Now that space allocated to the process in one go, is available for reallocation by the process without the hit of any new requests to the OS.

No transitions form user mode to kernel mode. One page fault.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.