/** * A utility method to register easily a {@link CustomDeallocator} with a Pointer. * * @param p the Pointer with which to register the deallocator * @return the Pointer */ protected static <P extends Pointer> P withDeallocator(P p) { return (P)p.deallocator(new CustomDeallocator(p)); }
/** * Called by native libraries to initialize the object fields. * * @param allocatedAddress the new address value of allocated native memory * @param allocatedCapacity the amount of elements allocated (initial limit and capacity) * @param deallocatorAddress the pointer to the native deallocation function * @see NativeDeallocator */ void init(long allocatedAddress, long allocatedCapacity, long ownerAddress, long deallocatorAddress) { address = allocatedAddress; position = 0; limit = allocatedCapacity; capacity = allocatedCapacity; if (ownerAddress != 0 && deallocatorAddress != 0) { deallocator(new NativeDeallocator(this, ownerAddress, deallocatorAddress)); } }