[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Apr 30 14:42:55 2003 
Subject:Re: Vector arguments to external procedures 
From:jlc 
Volume-ID:1030430.01 

Hi David,

> Dealing with garbage collections
> --------------------------------
> 
> Thanks for pointing this issue out Roger.
> 
> The problem is that if the address is found in user-level Pop, there
> might be a GC before it gets passed to the external procedure. This
> applies to all three methods above.

One way around this is to use an external procedure to allocate the memory,
instead of using the pop heap. That is, use malloc() to get the memory
for the vector or array.

It depends on what you are putting in these
structures how messy this might be (if it is just an array or numbers, it's
probably not too much hassle -- if you need pointers to pop objects, then
it gets more complicated).

If there are unwelcome interactions with poplog memory management, then
a way to do this is *once* when your program initialises itself, to allocate,
a *big* poplog vector, lock the poplog heap (once only) so it can't move,
then pass out this big vector to the external code. Then allocate space from
within this object.

This could certainly be made to work and would be efficient and safe, but
I can't remember whether it is easy to persuade standard C or C++ functions
to allocate from within a known address range. I assume you would prefer
not to write your own version of malloc() and free() ... ? :-) Although I confess
I probably *would* write my own jlc_malloc() and jlc_free(), since that would
be less effort than finding a better solution :-). But only if calling the system
malloc() interfered with Poplog in some way which mattered for the application.

Jonathan