13 messages in net.java.dev.jna.usersRe: [jna-users] Threading in JNA....
FromSent OnAttachments
Drayton BrownApr 6, 2009 3:40 am 
Timothy WallApr 6, 2009 5:24 am 
Drayton BrownApr 6, 2009 5:34 am 
Drayton BrownApr 6, 2009 9:28 am 
Timothy WallApr 6, 2009 9:50 am 
Drayton BrownApr 7, 2009 2:32 am 
Drayton BrownApr 9, 2009 3:20 am 
Timothy WallApr 13, 2009 6:11 am 
Drayton BrownApr 24, 2009 7:22 am 
Timothy WallApr 24, 2009 9:49 am 
Drayton BrownApr 28, 2009 5:42 am 
Timothy WallApr 28, 2009 6:44 am 
Drayton BrownApr 28, 2009 6:46 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Threading in JNA....Actions...
From:Drayton Brown (dray@gmail.com)
Date:Apr 7, 2009 2:32:52 am
List:net.java.dev.jna.users

Ok, thanks Timothy!

2009/4/6 Timothy Wall <twal@dev.java.net>

Native memory is allocated via malloc, not by requesting memory from the JVM. The only place JNA explicitly allocates memory is via the Memory object, which is used internally for backing Structures. Callbacks also allocate executable memory for small bits of trampoline code.

On Apr 6, 2009, at 12:28 PM, Drayton Brown wrote:

Hello again!

Just a quick question about how memory management works with JNA.

When starting the jvm I specify the size of the memory heap to be 2Gb. (I'm working on a 32bit machine, so this is the max I can use atm) Unfortunately the jvm crashes out while executing a native memory allocation function... (This only happens in some instances, so I'm confident that my code is ok since there are many instances where this does not happen)

Timing is everything. It's not necessarily a block of code that's incorrect, but how and when it operates within its environment.

My question is, when a native function allocates memory, does it take from

the memory allocated to the jvm, or does it do its own thing and ask the OS?

Thanks for any input!

Regards Drayton

2009/4/6 Drayton Brown <dray@gmail.com> Hello again Timothy!

The thread safe object is a native object written in C. I ensured this was thread safe by asking the third party developers to whom the object belongs...

I'll give the Native.synchronizedLibrary() call a try... I was not aware of this, so its probably just what I'm missing!

Thanks again Timothy!

Drayton

2009/4/6 Timothy Wall <twal@dev.java.net>

On Apr 6, 2009, at 6:41 AM, Drayton Brown wrote:

Hi all

I've written a threaded application which uses a thread safe shared object, however when I run the application with more that one thread, the jvm crashes out.

Is the "thread safe object" a Java object or a native one? What makes it thread safe?

I've checked the JNA site for information on how the JNA wrapper handles threading, but I've been unable to find any information. I was hoping someone on the mailing list could give me more information on the topic, or at least point me in the direction of the documentation on it.

JNA itself doesn't do anything special w/r/t threading. There is a Native.synchronizedLibrary() call that may be used to ensure any calls to your native library are serialized (i.e. no more than one call is ever active at any given time).

Return error codes are saved on a per-thread basis.