delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/07/31/18:04:35

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Sun, 31 Jul 2005 15:03:44 -0700
From: Yitzchak Scott-Thoennes <sthoenna AT efn DOT org>
To: cygwin AT cygwin DOT com
Subject: Re: heap_chunk_in_mb default value (Was Re: perl - segfault on "free unused scalar")
Message-ID: <20050731220344.GA2816@efn.org>
References: <23AA05B1B7171647BC38C5D761900EA40223C7E9 AT DF-SEADOG-MSG DOT exchange DOT corp DOT microsoft DOT com> <20050729170958 DOT GA872 AT efn DOT org> <dcdojc$rp4$1 AT sea DOT gmane DOT org>
Mime-Version: 1.0
In-Reply-To: <dcdojc$rp4$1@sea.gmane.org>
User-Agent: Mutt/1.4.2.1i
X-IsSubscribed: yes

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019