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


Groups > comp.lang.c > #65431

Re: lalloc() -- local stack allocation

Newsgroups comp.lang.c
Date 2015-07-12 11:12 -0700
References <e9abe69a-2532-44f3-be7b-aaa236783cfb@googlegroups.com> <fe75fd6a-a46e-42db-ac7c-3d9ab9fc8da0@googlegroups.com> <mntum4$pf0$1@news.albasani.net>
Message-ID <46cdebb4-86fa-43db-acd2-e3514cfb967d@googlegroups.com> (permalink)
Subject Re: lalloc() -- local stack allocation
From Malcolm McLean <malcolm.mclean5@btinternet.com>

Show all headers | View raw


On Sunday, July 12, 2015 at 3:47:45 PM UTC+1, Johannes Bauer wrote:
> On 12.07.2015 15:17, Malcolm McLean wrote:
> > On Sunday, July 12, 2015 at 10:24:10 AM UTC+1, Rick C. Hodgin wrote:
> >> Does C define a type of lalloc() function for local / stack allocation?
> >>
> > You can easily write your own.
> > It doesn't allocate on the function stack, but on its own private stack
> > that is a file scope global. You also need lfree(), and to be rigorous
> > in balancing allocations and frees.
> 
> Which completely defies the purpose of using the system stack. Because
> there you don't have to free because free is implicit at the end of a
> function scope when the stackframe is cleared.
> 
It's convenient  not to have to write pop_stack() before return,
but that's just a detail. The system stack is handy because it's
already available, and because it's likely to be in the cache.
The latter is a bit of a two edged sword if you're allocating 
large objects, because you can damage the cache coherence of the
stack by over-filling it.

> > Most functions that need dynamic memory for workspace rather than
> > for creating graphs lend themselves very easily to lalloc(),
> > lfree(), and the operations resolve to a few machine instructions.
> 
> A few machine instructions in userspace plus a few thousand instructions
> in kernel space where the actual memory is allocated in case there's a
> pagefault. No matter if on the stack or on the heap, there needs to be
> code somewhere which does the MMU programming.
> 
I don't believe that. The lalloc() stack is simply a global buffer,
accessing it is no different to write access to any global object via pointer:offset where the system can't determine that the offset 
variable is bounded within the page at compile time.
You can also easily implement your own stack overflow protection.
It's a single comparison.

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


Thread

lalloc() -- local stack allocation "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-12 02:23 -0700
  Re: lalloc() -- local stack allocation Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-07-12 11:48 +0200
    Re: lalloc() -- local stack allocation Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-07-12 11:48 +0200
  Re: lalloc() -- local stack allocation Philipp Klaus Krause <pkk@spth.de> - 2015-07-12 13:33 +0200
  Re: lalloc() -- local stack allocation Robert Wessel <robertwessel2@yahoo.com> - 2015-07-12 06:54 -0500
  Re: lalloc() -- local stack allocation Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-07-12 06:17 -0700
    Re: lalloc() -- local stack allocation Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-07-12 16:47 +0200
      Re: lalloc() -- local stack allocation Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-07-12 11:12 -0700
      Re: lalloc() -- local stack allocation supercat@casperkitty.com - 2015-09-08 11:53 -0700
        Re: lalloc() -- local stack allocation "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-08 12:16 -0700
          Re: lalloc() -- local stack allocation supercat@casperkitty.com - 2015-09-08 15:46 -0700
            Re: lalloc() -- local stack allocation "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-08 16:12 -0700
        Re: lalloc() -- local stack allocation Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-08 20:32 +0100
        Re: lalloc() -- local stack allocation jadill33@gmail.com - 2015-09-08 13:25 -0700
  Re: lalloc() -- local stack allocation "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-12 10:17 -0700
  Re: lalloc() -- local stack allocation gordonb.zziiu@burditt.org (Gordon Burditt) - 2015-07-27 22:41 -0500
    Re: lalloc() -- local stack allocation Keith Thompson <kst-u@mib.org> - 2015-07-28 08:35 -0700

csiph-web