0

If so please provide an example and also how to free the memory once created.

I imagine it might be possible using the Unsafe instance?

newlogic
  • 807
  • 8
  • 25
  • Is there some reason you'd want to do this? – Ceiling Gecko Jun 26 '14 at 14:05
  • Does this article answer the question? http://java.dzone.com/articles/sunmiscunsafe-and-heap-memory – DNA Jun 26 '14 at 14:10
  • @CeilingGecko, yes its too reduce the dependancy on the Java garbage collector, in order to reduce latency costs incurred by garbage collection. – newlogic Jun 26 '14 at 14:17
  • @DNA nope that doesn't help, that shows how to allocate and free Java objects on-heap using the UnSafe instance, and how to allocate and free Java primatives off-heap using the UnSafe instance, but not how to allocate and free Java Objects off-heap. – newlogic Jun 26 '14 at 14:19

1 Answers1

0

You are probably looking for a Pool object.

Essentially - going off-heap is complex and system-dependent. However, if you pre-allocate a pool of objects you can take them and return them atomically. It would certainly ensure a more fixed and predictable latency but it would not guarantee it.

Community
  • 1
  • 1
OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213