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.