chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Stack space allocation


From: John Lenz
Subject: Re: [Chicken-users] Stack space allocation
Date: Mon, 22 Mar 2004 21:25:44 -0600

What I am concerned about is alloca calls inside a C block. I am unsure if the compiler might be optimizing stack space. That is, since I create three blocks, it would assume that stack space can be shared between them and then the alloca call would return the same space to all three blocks.

Yes, I agree that this might be dangerous. It's preferable to alloc all
the storage at once. C_pair will update the known_space pointer
accordingly on every initialization.

Well, after a bunch of searching, I found this
http://www.gnu.org/software/libc/manual/html_node/GNU-C-Variable-Size-Arrays.html

which seems to imply that alloca persists until the function returns, unlike arrays which last until the end of the block. The man page for alloca also states that the memory persists until the end of the function call. So I will write the SWIG interface functions to assume that alloca will always be unique.


It usually is (even though it doesn't _have_ to be). If you can be sure that the compiler wont optimize things away (and I don't know right now), then
the former approach might be ok.
Are the lists potentially very long?

Well, this is for the SWIG wrapper, so the list will be as long as whoever is using SWIG inputs. Ideally, we would not like to place restrictions on the size, so that SWIG will work for whatever purpose. Is there a better way to allocate data space? alloca works for things like return values and a few paramaters, but for very long lists, it is probably a bad idea to stick all that allocation on the stack. (maybe it is a good idea...?)

John




reply via email to

[Prev in Thread] Current Thread [Next in Thread]