This is the mail archive of the java-discuss@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: alloca and native code


Oskar Liljeblad wrote:
> Is it ok to use alloca from native code?

I think so.  There may be some portability issues; i.e. some OSes need alloca.h,
some don't have it:

#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif

> I want to allocate a piece
> of memory which isn't scanned or collected by the GC, which is freed
> when the (native implementation of the) method returns.

Memory reserved with alloca() _will_ be scanned by boehm-gc, like the rest of
the stack.  To avoid that, you could allocate memory with _Jv_AllocBytes
instead.  I don't remember if that function is exported, however.

--
Jeff Sturm
jeff.sturm@appnet.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]