zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: Re: argv subscript range uses too many memory
Date: Sat, 10 Nov 2012 21:16:12 +0000	[thread overview]
Message-ID: <20121110211612.436c5ce3@pws-pc.ntlworld.com> (raw)
In-Reply-To: <121110065709.ZM4781@torch.brasslantern.com>

On Sat, 10 Nov 2012 06:57:09 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> Further discussion probably should be re-routed to zsh-workers.

I've done that.
 
> 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.

What's puzzling me is that loops, including the "while" involved here,
execute freeheap() at the end of each iteration.  That should restore the pristine state of the loop when it was pushed each time around, shouldn't it?  Maybe I'm missing some subtlety of freeheap().

I'm a little bit worried there might be some pathology with permanent,
i.e. non-heap, allocation, in particular with zsh's own implementation
of malloc() (though I don't think anyone's compared between system and
zsh versions).  That would be something along the lines of: each time
around the loop we create an array that is just a little bit bigger than
the one we created last time, so doesn't fit in the memory we freed, so
we allocate yet another chunk of memory.  That's probably nonsense
because (i) if we allocated another chunk, the combination of the that
with the previous one would be order twice as large as the original, so
we shouldn't see pathological behaviour unless something was doubling
each time, and there's nothing obviously like that in this case (ii)
indeed we're looking at arrays getting smaller each time.  Still, I
can't quite get this out of my head.  That's probably because my head's
a funny shape inside.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


       reply	other threads:[~2012-11-10 21:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20121108084001.GA7594@localhost.localdomain>
     [not found] ` <20121108100226.575b0788@pwslap01u.europe.root.pri>
     [not found]   ` <20121110105811.GA7136@localhost.localdomain>
     [not found]     ` <121110065709.ZM4781@torch.brasslantern.com>
2012-11-10 21:16       ` Peter Stephenson [this message]
     [not found]       ` <20121120130457.GD2500@localhost.localdomain>
     [not found]         ` <121120090300.ZM5552@torch.brasslantern.com>
2012-11-20 17:44           ` Bart Schaefer
2012-11-20 18:24             ` Bart Schaefer
2012-11-22  9:28               ` Han Pingtian
2012-11-22 18:29                 ` Bart Schaefer
2012-11-25  8:11                   ` Han Pingtian
2012-11-25 19:03                     ` Bart Schaefer
2012-11-29 23:37                       ` Han Pingtian
2012-11-20 21:05             ` Peter Stephenson
2012-11-20 23:22               ` Bart Schaefer
2012-11-22 22:33                 ` Han Pingtian

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=20121110211612.436c5ce3@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@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).