Remix.run Logo
riku_iki 3 days ago

Not sure about .NET, but Java doesn't have arenas..

pjmlp 3 days ago | parent | next [-]

It surely has them since Project Panama, as memory segments.

metaltyphoon 3 days ago | parent | prev | next [-]

It’s this simple in .NET

   ArrayPool<T>
riku_iki 3 days ago | parent [-]

will elements of arraypool still be tracked by GC with overhead?

pjmlp 3 days ago | parent [-]

Depends on the T.

.NET has value types, explicit stack allocation, low level unsafe programming C style, and manual memory management as well.

kernal 3 days ago | parent | prev [-]

java.lang.foreign.Arena

riku_iki 3 days ago | parent [-]

My understanding is that that arena allows you to allocate memory segments, but you can't do much with it, you can't allocate var or object on it like in C++ for example, so its almost useless.

kernal 2 days ago | parent | next [-]

https://docs.oracle.com/en/java/javase/21/core/memory-segmen...

riku_iki 2 days ago | parent [-]

That Arena is not integrated into language. You can't do something like:

var myObj = new(my_arena) MyClass();

pjmlp 3 days ago | parent | prev [-]

You certainly can, as they were designed as JNI replacement, with the goal to fully support the C ABI of the host platform.

You can either do the whole boilerplate manually with Panama set of APIs, or write a C header file and let jextract do the work of boilerplate generation.

riku_iki 2 days ago | parent [-]

> You certainly can

I am wondering if there is working code example, or this is just speculation?