ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl5-porters
perl5-porters
Re: Memory allocation in 5.6
by Yitzchak Scott-Thoennes other posts by this author
Sep 29 2000 10:11AM messages near this date
Memory allocation in 5.6 | how does 'for my $x (LIST)' alias?
In article <v0422080cb5f99c3355cf@[192.168.0.4]> ,
"Marc D. Spencer" <marcs@[...].com>  wrote:
>  my $foo = 'x' x ($ARGV[0] * 1024000);
>  sleep $ARGV[1] if $ARGV[1];
>  print "Released.\n";
>  
>  seems to allocate twice the memory I ask it for. This wouldn't be a 
>  problem, except I'm manipulating images in scalars, so they can be 
>  large.

The x operator has pad space allocated to it to store its result in.
(The same is true of most other operators.)  This is not freed and
gets reused each time the code is run through.

You could try:

my $foo = 'x';
$foo x= ($ARGV[0] * 1024000);

If that also doubles the space, try:

sub repeater($$) { my ($str, $count) = @_; sub { $str x $count } }
my $foo = &{&repeater('x', $ARGV[0] * 1024000)}

This should free the extra memory right away (to your program, not
back to the system).  But I'm not sure that it won't allocate triple
the memory to your program.
Thread:
Marc D. Spencer
Yitzchak Scott-Thoennes

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved