Date: Thu, 13 Sep 2001 20:12:50 GMT From: cfedde@fedde.littleton.co.us (Chris Fedde) Subject: Re: How to preallocate memory for my perl script (UNIX) Message-Id: <6r8o7.382$Owe.252165632@news.frii.net> In article , Tad McClellan wrote: >Stan Brown wrote: >> >>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) > While there are often good reasons for holding a large dataset in memory. There are often alternatives that can use much less memory. For example processing one row at a time using the DBI::fetchrow_* methods rather than loading the whole result using the DBI::fetchall_* into memory just to walk it and then throw it away. YMMV chris -- This space intentionally left blank