Skip to content

Instantly share code, notes, and snippets.

@burtonator
Created July 25, 2013 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burtonator/6076790 to your computer and use it in GitHub Desktop.
Save burtonator/6076790 to your computer and use it in GitHub Desktop.
DirectByteBuffer(int cap) { // package-private
super(-1, 0, cap, cap, false);
Bits.reserveMemory( cap );
int ps = Bits.pageSize();
long base = 0;
try {
base = unsafe.allocateMemory(cap + ps);
} catch (OutOfMemoryError x) {
Bits.unreserveMemory(cap);
throw x;
}
unsafe.setMemory(base, cap + ps, (byte) 0);
if (base % ps != 0) {
// Round up to page boundary
address = base + ps - (base & (ps - 1));
} else {
address = base;
}
cleaner = Cleaner.create( this, new Deallocator( base, cap ) );
viewedBuffer = null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment