www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - alloca and GC

reply "Carlos Santander B." <csantander619 gmail.com> writes:
Is memory assigned by alloca garbage collected? Because std.process uses
alloca, 
but doesn't use free.

-----------------------
Carlos Santander Bernal 
Nov 21 2004
next sibling parent reply Dave <Dave_member pathlink.com> writes:
In article <cnrkh1$fo2$1 digitaldaemon.com>, Carlos Santander B. says...
Is memory assigned by alloca garbage collected? Because std.process uses
alloca, 
but doesn't use free.

-----------------------
Carlos Santander Bernal 

Check this out: http://www.rt.com/man/alloca.3.html
Nov 21 2004
parent "Carlos Santander B." <csantander619 gmail.com> writes:
"Dave" <Dave_member pathlink.com> escribió en el mensaje 
news:cnrq0b$o40$1 digitaldaemon.com...
| In article <cnrkh1$fo2$1 digitaldaemon.com>, Carlos Santander B. says...
| >
| >Is memory assigned by alloca garbage collected? Because std.process uses 
alloca,
| >but doesn't use free.
| >
| >-----------------------
| >Carlos Santander Bernal
| >
| >
|
| Check this out:
|
| http://www.rt.com/man/alloca.3.html
|
|

Thanks, Dave and Ilya.

-----------------------
Carlos Santander Bernal 
Nov 22 2004
prev sibling parent reply Ilya Minkov <minkov cs.tum.edu> writes:
Carlos Santander B. schrieb:

 Is memory assigned by alloca garbage collected? Because std.process uses
alloca, 
 but doesn't use free.

Alloca allocates memory using stack pointer increment. This memory is reclaimed when you return from a function and the stack pointer is set back to what it was. Alloca is the fastest way to allocate memory. Another funny thing is, since stack is a GC root, the memory you get using alloca also is - so it is safe to store pointers to GCed memory there as well. -eye
Nov 22 2004
parent reply Ilya Minkov <minkov cs.tum.edu> writes:
Ilya Minkov schrieb:

 Alloca allocates memory using stack pointer increment. This memory is 

ARGH, decrement, not increment. Because stack grows top-down. -eye.
Nov 22 2004
parent "Simon Buchan" <currently no.where> writes:
On Mon, 22 Nov 2004 17:18:04 +0100, Ilya Minkov <minkov cs.tum.edu> wrote:

 Ilya Minkov schrieb:

 Alloca allocates memory using stack pointer increment. This memory is

ARGH, decrement, not increment. Because stack grows top-down. -eye.

Most of the time :D. It is _possible_ to get it to grow up, I believe, and don't quote me on it, but I suspect other architectures have their own conventions. -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 22 2004