Date: Thu, 13 Sep 2001 14:09:51 GMT From: tadmc@augustmail.com (Tad McClellan) Subject: Re: How to preallocate memory for my perl script (UNIX) Message-Id: Stan Brown wrote: >I have a perl script that retrieves a fairly large amount of data from >Oracle. I'm trying to speed it up. > >I have obsered that the first time I do a lareg fetch, and store it in a >perl variable, What kind of variable? Array? Hash? >the process size of the script slowy increases. Now ehen I >do a second query, it runs _much_ faster. > >I beleive that a part of this is because perl has to make many small >requests to the OS for emeory, the first time. So I would like to do >something, before the first fetch to get perl to request a large chunk of >memory from the OS, the undefine whatever is using this memeory, thus >making that memory available to perl for reuse. > >Sugestions? You can preallocate memory: my @array; $#array = 1_000_000; # a million elements or my %hash; keys %hash = 1_000_000; # a million buckets (perldata.pod) And empty it out when you are done: @array=(); # keep the large memory associated with @array 'cause # you're going to use it again undef @array; # return memory to perl process, no longer associated # with the array, will need to realloc when you # reuse the same array (so don't do this) -- Tad McClellan SGML consulting tadmc@augustmail.com Perl programming Fort Worth, Texas