This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: heap_chunk_in_mb default value (Was Re: perl - segfault on "free unused scalar")


On Fri, Jul 29, 2005 at 07:21:44PM +0200, Krzysztof Duleba wrote:
> Yitzchak Scott-Thoennes wrote:
> 
> >However code like the above does end up using twice the space; it's
> >allocated once to store the result of the x operation and again when
> >it's copied to $a.
> 
> Really? I hope you're wrong. Avoiding copy operation while declaring a new 
> variable with a value is a very important optimization.

Patches welcome.  http://perldoc.perl.org/perlhack.html

There are some optimizations in this area; if you do something like:

   perl -we'sub foo { "a" x (1024 * 1024) }  $bar = foo()'

The assignment doesn't actually copy, it just replaces $bar's string
buffer with the one from foo()'s return value, but I'm pretty sure
returning a value from a subroutine itself involves a copy.

For some operations, an assignment of the result of the operation to
a lexical can be optimized away in code that looks like this:

   perl -we'my $foo;  $foo = "bar: " . ("a" x (1024 * 1024))'

Extending this to work for x is possible in principle, but complicated
by the two different modes of x (list and scalar).  See "Some comments
about 'T'" in opcode.pl and Perl_ck_sassign in op.c in the perl
source.

This optimization only applies to already existing lexicals, not to
ones just being declared or to package variables.

In 5.9.x, there is experimental "copy on write" code that may suppress
the copy in your situation.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]