简体   繁体   English

是否可以为Java对象的堆外分配和释​​放内存空间?

[英]Is it possible to allocate and free memory space for a Java Object off-heap?

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? 我想使用Unsafe实例有可能吗?

You are probably looking for a Pool object. 您可能正在寻找Pool对象。

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. 当然可以确保更固定和可预测的延迟,但不能保证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM