Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c > #1660

Re: VLAs use less stack

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Jens Gustedt <jens.gustedt@loria.fr>
Newsgroups comp.std.c
Subject Re: VLAs use less stack
Date Tue, 04 Sep 2012 10:28:56 +0200
Organization A noiseless patient Spider
Lines 43
Message-ID <5045BBC8.7040303@loria.fr> (permalink)
References <k1q5bu$49h$1@speranza.aioe.org> <lnsjb2ucn5.fsf@nuthaus.mib.org> <k2034n$jb5$1@reader1.panix.com> <lnd324glvw.fsf@nuthaus.mib.org> <k23iks$ktu$1@reader1.panix.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-15
Content-Transfer-Encoding 7bit
Injection-Info mx04.eternal-september.org; posting-host="2590e4fa64e7931a8f955de6703c052f"; logging-data="3453"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NujeD9oG9YCByVMqbWlbwn/1N4xrTFR8="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0
In-Reply-To <k23iks$ktu$1@reader1.panix.com>
Cancel-Lock sha1:H1qXJPwiq+2SUS8qSQo6n4DlpQM=
Xref csiph.com comp.std.c:1660

Show key headers only | View raw


Am 04.09.2012 02:39, schrieb Joe keane:
> In article <lnd324glvw.fsf@nuthaus.mib.org>,
> Keith Thompson  <kst-u@mib.org> wrote:
>> I was referring to *just* using malloc(), realloc(), and free(),
>> even for small allocations, as opposed to falling back to malloc()
>> for large buffers.
> 
> So we are clear:
> 
> a. fixed-size array only
> b. variable-size array only
> c. malloc and free only
> d. fixed-size array with malloc and free backup
> e. variable-size array with malloc and free backup
> 
> Options 'a' and 'b' are easy: they don't work.
> 
> Option 'c' is 'better', it works, except it may be slow.  Generally
> speaking i prefer code that is slow to code that doesn't work.
> 
> Option 'd' is 'better'.
> 
> But you shouldn't bother with it unless you have some reason to think
> it's needed, either some evidence, or the fact that it has proven useful
> in some other situation, such that it would be less time to code it that
> way in the first place, rather than test it and find that it's a problem
> and then fix it.
> 
> I don't think that 'e' really buys you a lot versus 'd'.

It really would depend on the use pattern. If the function is
recursive and the average size of the allocation is small, say some
value x, this could be worth doing. You could put the cut off at 10*x
and the malloc case would appear "almost never", by still having a
stack use of x on average, instead of 10*x. Then you could go deeper
into recursion and maybe even more important the cache behavior could
be a bit better.

But I agree that these are a lot of hypothesis.

Jens

Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

VLAs use less stack jacob navia <jacob@spamsink.net> - 2012-08-31 12:58 +0200
  Re: VLAs use less stack Marc <marc.glisse@gmail.com> - 2012-08-31 14:10 +0000
    Re: VLAs use less stack Marc <marc.glisse@gmail.com> - 2012-08-31 14:13 +0000
    Re: VLAs use less stack jacob navia <jacob@spamsink.net> - 2012-08-31 18:09 +0200
    Re: VLAs use less stack jacob navia <jacob@spamsink.net> - 2012-08-31 18:14 +0200
    Re: VLAs use less stack John Nagle <nagle@animats.com> - 2012-09-01 12:24 -0700
      Re: VLAs use less stack jacob navia <jacob@spamsink.net> - 2012-09-01 22:57 +0200
      Re: VLAs use less stack jacob navia <jacob@spamsink.net> - 2012-09-01 22:59 +0200
  Re: VLAs use less stack Keith Thompson <kst-u@mib.org> - 2012-08-31 11:42 -0700
    Re: VLAs use less stack Marc <marc.glisse@gmail.com> - 2012-09-01 10:18 +0000
      Re: VLAs use less stack Rui Maciel <rui.maciel@gmail.com> - 2012-09-01 19:18 +0100
        Re: VLAs use less stack Marc <marc.glisse@gmail.com> - 2012-09-01 19:19 +0000
        Re: VLAs use less stack jacob navia <jacob@spamsink.net> - 2012-09-01 23:01 +0200
      Re: VLAs use less stack Keith Thompson <kst-u@mib.org> - 2012-09-01 11:36 -0700
        Re: VLAs use less stack Marc <marc.glisse@gmail.com> - 2012-09-01 19:05 +0000
    Re: VLAs use less stack jgk@panix.com (Joe keane) - 2012-09-02 16:56 +0000
      Re: VLAs use less stack Keith Thompson <kst-u@mib.org> - 2012-09-02 14:22 -0700
        Re: VLAs use less stack jgk@panix.com (Joe keane) - 2012-09-04 00:39 +0000
          Re: VLAs use less stack Jens Gustedt <jens.gustedt@loria.fr> - 2012-09-04 10:28 +0200
            Re: VLAs use less stack John Nagle <nagle@animats.com> - 2012-09-04 11:31 -0700
          Re: VLAs use less stack jacob navia <jacob@spamsink.net> - 2012-09-04 17:02 +0200
      Re: VLAs use less stack jacob navia <jacob@spamsink.net> - 2012-09-02 23:28 +0200
      Re: VLAs use less stack Keith Thompson <kst-u@mib.org> - 2012-09-02 14:37 -0700
        Re: VLAs use less stack John Nagle <nagle@animats.com> - 2012-09-02 15:45 -0700
          Re: VLAs use less stack Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-09-04 00:03 +0200
  Re: VLAs use less stack jgk@panix.com (Joe keane) - 2012-09-01 16:09 +0000
    Re: VLAs use less stack Keith Thompson <kst-u@mib.org> - 2012-09-01 11:45 -0700
    Re: VLAs use less stack jacob navia <jacob@spamsink.net> - 2012-09-01 23:05 +0200

csiph-web