2 messages in net.java.dev.jna.usersRe: [jna-users] Tip o' the day: Large...
FromSent OnAttachments
Timothy WallSep 11, 2008 6:22 pm 
ArgynSep 11, 2008 9:08 pm 
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] Tip o' the day: Large Structure performanceActions...
From:Argyn (jawa@gmail.com)
Date:Sep 11, 2008 9:08:12 pm
List:net.java.dev.jna.users

On Thu, Sep 11, 2008 at 9:22 PM, Timothy Wall <twal@dev.java.net> wrote:

If you're using very large structures and using them often, here's a tip that can boost performance by several orders of magnitude. Note that you should follow this tip *only* if you really need the performance boost; otherwise you may wind up obfuscating your code.

By default, when JNA makes a native call it will copy the full contents of a Java Structure to native memory prior to the call and read it all back after the call. If your Structure is very large, this can result in significant overhead reflecting all the fields of the Structure. The reflection dwarfs the actual native communication time.

this seems to apply to my situation. before using JNA, I was using my customized version of shared stubs, where struct was not really being marshalled-unmarshalled on each call.

maybe there should be some kind of a "lazy" Structure. that would require some re-factoring though. i'd require java beans style get/set naming convention for structure fields (instead of public fields), then inside those getters implement the lazy accessors.