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: Tue, 23 Mar 2004 07:47:57 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113

John Lenz wrote:

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.

Fine.



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.

Agreed.

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...?)

You can use C_alloc_in_heap(). But the cleanest solution is to mimick the
way compiled code allocates it's "literal frame":

- use C_demand2() to check whether there is enough space on the heap
- if there isn't enough space, invoke "C_rereclaim2(<needed storage>, 1);"
- if there is, invoke C_pair() (and friends) with the allocation pointer
  C_heaptop (like: "mypair = C_pair(C_heaptop, car, cdr);")


cheers,
felix




reply via email to

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