java - GetDirectBufferAddress: Address out by 4 -


i attempting pass bytebuffer java native code in android. consistantly getting returned memory address starting @ index 4.

i have tested across various devices , array same size across java , jni when calling getdirectbuffercapacity.

why offset occuring?

java:

inputbuffer = bytebuffer.allocatedirect(inputbuffersize); 

jni:

uint8_t* inputbuffer = (uint8_t*) env->getdirectbufferaddress(inputbytebuffer); 

the given memory address offset 4 bytes , moving pointer array match (as shown below).

uint8_t* inputbuffer = (uint8_t*) env->getdirectbufferaddress(inputbytebuffer) - 4; 

the address returned effective address, based upon alignment of buffer. code (copyright aosp, rights reserved) looks this:

public static bytebuffer allocatedirect(int capacity) {     if (capacity < 0) {         throw new illegalargumentexception("capacity < 0: " + capacity);     }     // ensure alignment 8.     memoryblock memoryblock = memoryblock.allocate(capacity + 7);     long address = memoryblock.tolong();     long alignedaddress = (address + 7) & ~(long)7;     return new directbytebuffer(memoryblock, capacity, (int)(alignedaddress - address), false, null); } 

when direct address, effective address, aligned, while actual buffer not aligned.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -