zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: argv subscript range uses too many memory
Date: Sat, 10 Nov 2012 06:57:09 -0800	[thread overview]
Message-ID: <121110065709.ZM4781@torch.brasslantern.com> (raw)
In-Reply-To: <20121110105811.GA7136@localhost.localdomain>

Further discussion probably should be re-routed to zsh-workers.

On Nov 10,  6:58pm, Han Pingtian wrote:
}
} Looks like when running with 'print -- "$argv[1,3]", the call trace is
} something like this:
} 
} (gdb) bt
} #0  mmap_heap_alloc (n=0x7fff0852e880) at mem.c:449
} #1  0x000000000045f5f9 in zhalloc (size=1594456) at mem.c:542
} #2  0x00000000004a4dfa in arrdup (s=0x313b008) at utils.c:3648
} #3  0x0000000000471fa9 in getarrvalue (v=0x7fff0852ea20) at params.c:2174

Ah, yes.  Array slices are implemented by copying the entire array and
then extracting the desired subset from the copy.  Individual array
elements are string references and therefore copy only the one element.

Unfortunately this is pretty deeply ingrained in zsh's parameter
expansion implementation and likely requires some serious rewriting to
fix.  It might be easier to come up with a way to garbage-collect more
frequently.

In a loop, the heap allocations are not popped until the loop is done,
IIRC, so you'll end up with a large number of copies of the original
array in the heap with slice results pointing into different parts of
each copy.  Maybe there's a narrower scope in which a pushheap/popheap
could be inserted.


  reply	other threads:[~2012-11-10 14:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-08  8:40 Han Pingtian
2012-11-08 10:02 ` Peter Stephenson
2012-11-10 10:58   ` Han Pingtian
2012-11-10 14:57     ` Bart Schaefer [this message]
2012-11-20 13:04       ` Han Pingtian
2012-11-20 17:03         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=121110065709.ZM4781@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).