top | item 45402764

(no title)

kaibutsu | 5 months ago

You can write an arena allocator referencing a pointer allocated via Marshal.AllocHGlobal and proxying it via Span<T> very easily in literally like 30 lines of code which will achieve whatever you're suggesting there, can also add where T: unmanaged if you don't want the ability to reference things which can be tracked by the GC, this is already possible right now and is fully enforced.

You can add 30 more lines of code to your arena with some PInvoking on windows calling AddVectoredExceptionHandler and VirtualAlloc, which will allow you to allocate whatever amount of memory you'd like without actually committing it, creating a very optimized and easy to use alternative to whatever you're suggesting.

discuss

order

kikimora|5 months ago

The only problem I see with this approach is lack of standard data structures allocated in native memory. In GC memory you have collections and strings. In native memory you would have to create such data structures yourself. Plus figure out interoperability between the two.

axx83|4 months ago

You've hit on the exact problem. The friction of interoperability is the real wall.

Now, imagine if that friction disappeared. Imagine 90% of your codebase is safe, using traditional collections and strings, while only the critical 10% uses high-performance, native data types. What if moving between these two worlds was a natural, compiler-guaranteed feature, not a manual, error-prone task? How amazing would that be?

This vision of seamless coexistence is the core of my proposal. I've detailed it in a new, more focused post and would love for you to take a look.

https://news.ycombinator.com/item?id=45477324