Native Julia API for Memory Allocations #49506
Replies: 3 comments 11 replies
-
I really do think we need to study Java's new foreign memory API closely to both not reinvent the wheel and avoid the same mistakes. Java is a garbage collected language that is quite pointer heavy. It uses layouts similar to your https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/lang/foreign/MemorySession.html |
Beta Was this translation helpful? Give feedback.
-
What does |
Beta Was this translation helpful? Give feedback.
-
This is an interesting reference on how Rust is developing its allocation protocols https://github.com/rust-lang/rfcs/pull/1398/files |
Beta Was this translation helpful? Give feedback.
-
While working on #48728 I've found out a couple things that may have pretty big implications and the limitations of Julia (some of this may be obvious to core devs here, so I apologize if I'm missing the mark a bit on any of this). It's possible to get and set values to a previously allocated block of memory all in native Julia (although this is likely not intended to be a stable interface and takes some careful work to accomplish with decent performance). This does require some extra calls to C
for boxed values (
jl_value_ptr
andjl_gc_queue_root
), but seems to work without any errors. This can be used to push Julia's performance and more generally is in line with Julia's philosophy of solving the two language problem. However, the ability to manual intervene in memory using Julia stops as soon as (re)allocating memory is involved.It's impractical to wholly rely on a dedicated memory allocation type from
Base
that is essentiallyThis precludes other potential layouts such as something table-like
I won't belabor the variety of layouts anymore than this, but the point stands that Julia really needs to have a method to accommodate more flexibility in allocating blocks of memory itself.
I understand that the underlying management of memory in Julia is subject to change and undergoing continual optimization at this time, making commitment to any API at this time difficult. However, even something as minimal as
GC.alloc
and/orGC.realloc
would be extremely helpful. This wouldn't commit to any specific heap vs stack allocation schema but would allow moving a lot more code to native Julia.I figure that ordinary pointers would be an issue since we still want the GC to track this chunk of memory. Maybe if we had something that was equivalent to
mutable struct OpaqueMemoryChunk end
?Beta Was this translation helpful? Give feedback.
All reactions