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: felix
Subject: Re: [Chicken-users] Stack space allocation
Date: Mon, 22 Mar 2004 22:40:29 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113

John Lenz wrote:
Hi. I am in the process of redoing the swig stuff, and I have a question about C_alloc.

Would the following code be valid?


[...]


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.


Also, when wrapping say a std::list I would like to do something like
for (i = list.begin(); i != list.end(); ++i) {
 C_word *space = C_alloc(C_SIZEOF_PAIR + C_SIZEOF_SWIG_POINTER);
 C_pair(...);
}
would that also be acceptable? The compiler won't optimize the stack space usage so that every iteration has new data space.

or would say
C_word *space = C_alloc((C_SIZEOF_PAIR + C_SIZEOF_SWIG_POINTER) * list. size());
and allocate it all at once work better?
Note the list.size() is a O(n) operation.


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?


cheers,
felix




reply via email to

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