Ross,

> Here is the 
> problem the amount of memory allocated is very close to being 
> 3 times the size of the hash tables. even if I undef 
> %Original_Hash twice. 

I think you're confusing a few issues here. 

Q1) When if ever does Perl return memory back to Windows for other
applications?
A1) For most cases, this is only when the entire perl program ends. There
are ways around this but it's out of scope for this question.

Q2) When, if ever, does Perl return memory back to perl for re-use for other
data structures within the current application?
A2) When *all* references to the data structure are "undef"ed or go out of
scope. In your example %alpha will "keep alive" all of the referenced
objects in the values of %orig. Note reassigning a hash to another hash will
not reduce the memory allocated to this hash. Run this to see how many used
vs allocated "buckets" perl is maintaining in the hash.

%x = ("Cat",1,"Dog",2);  print scalar(%x),"\n";
@x{@1..10000}=(1)x10000; print scalar(%x),"\n";
%x = ("Cat",1,"Dog",2);  print scalar(%x),"\n";
undef %x;                        print scalar(%x),"\n";
%x = ("Cat",1,"Dog",2);  print scalar(%x),"\n";

Q3) When, if ever, does Perl return memory back to perl for re-use within
the same data structure?
This is a black art know by the mystical gods with hallowed names like Wall,
Christiansen, and Schwartz.  There are many wonderful optimisations to make
programs go faster or use less memory. From a programmers point we can't
really assume much more than optimisation than what we know from Q2. So as a
rule only declare your data within the minimum scope required to get the job
done.

my @files=<*.*>;
# Don't declare %data here!
for my $file (@files) {
        open IN, $file or die "toasted: opening $file  $!";
        # Declare %data here instead!
        my %data;
        while (<IN>) {
                chomp;
                @details=split/,/;
                my $key =shift @details;
                $data{$key}=\@details;
        }
        DoStuff(\%data)
        # %data and all objects that it alone refers to 
      # will be magically garbage collected for reuse by this Perl program.
}

If you want to know exactly how much memory Perl is using for a particular
variable then I'm all out of ideas. I posted a similar question to this list
a year or so ago and came up blank.

http://aspn.activestate.com/ASPN/Mail/Message/922634


HTH

Alistair


-----------------------------------------------------------------------


Registered Office:
Marks & Spencer p.l.c
Michael House, Baker Street,
London, W1U 8EP
Registered No. 214436 in England and Wales.

Telephone (020) 7935 4422 
Facsimile (020) 7487 2670

www.marksandspencer.com

Please note that electronic mail may be monitored.

This e-mail is confidential. If you received it by mistake, please let us know and 
then delete it from your system; you should not copy, disclose, or distribute its 
contents to anyone nor act in reliance on this e-mail, as this is prohibited and may 
be unlawful.

The registered office of Marks and Spencer Financial Services PLC, Marks and Spencer 
Unit Trust Management Limited, Marks and Spencer Life Assurance Limited and Marks and 
Spencer Savings and Investments Limited is Kings Meadow, Chester, CH99 9FB.

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to