Skip to content

Instantly share code, notes, and snippets.

@bandrzejczak
Created February 9, 2018 22:07
Show Gist options
  • Save bandrzejczak/ad75ffb9980b37a35d066f2fcc31a156 to your computer and use it in GitHub Desktop.
Save bandrzejczak/ad75ffb9980b37a35d066f2fcc31a156 to your computer and use it in GitHub Desktop.
private static class UnsafeTrade {
private static long offset = 0;
private static final long ticketOffset = offset += 0;
private static final long amountOffset = offset += 4;
private static final long priceOffset = offset += 4;
private static final long buyOffset = offset += 4;
private static final long objectSize = offset += 1;
private long objectOffset;
public static long getObjectSize() {
return objectSize;
}
void setObjectOffset(final long objectOffset) {
this.objectOffset = objectOffset;
}
public void setTicket(final int ticket) {
unsafe.putInt(objectOffset + ticketOffset, ticket);
}
public long getPrice() {
return unsafe.getInt(objectOffset + priceOffset);
}
public void setPrice(final int price) {
unsafe.putInt(objectOffset + priceOffset, price);
}
//other getters and setters
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment