3 messages in net.java.dev.jna.usersRe: [jna-users] Re: Copy from one poi...
FromSent OnAttachments
Duncan McGregorJun 19, 2008 1:31 am 
Duncan McGregorJun 19, 2008 3:19 pm 
Michael Brewer-DavisJun 20, 2008 11:04 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] Re: Copy from one pointer to anotherActions...
From:Michael Brewer-Davis (mich@tech4learning.com)
Date:Jun 20, 2008 11:04:29 am
List:net.java.dev.jna.users

Not sure what your overall use case is here. Do you need two copies of the memory or one at the end? Are Structure.useMemory() or Memory.share() options?

michael

Duncan McGregor wrote:

On 19 Jun 2008, at 09:31, Duncan McGregor wrote:

I need to load a Structure from an existing pointer. Is there any more straightforward way than my current

Pointer pointerToResult = buffer.getPointer(0); Structure result = javaParameterType.newInstance(); byte[] structBytes = new byte[result.size()]; pointerToResult.read(0, structBytes, 0, structBytes.length); Pointer structMemory = result.getPointer(); structMemory.write(0, structBytes, 0, structBytes.length); result.read();

Answering my own question, this also works

private void memcpyViaByteBuffer(Pointer dest, Pointer src, int byteCount) { ByteBuffer destBuffer = dest.getByteBuffer(0, byteCount); ByteBuffer srcBuffer = src.getByteBuffer(0, byteCount); destBuffer.put(srcBuffer); }

I can't help thinking that the API is missing something in this area though.