Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can do that, and people do. However a GC language doesn't normally give you the flexibility of getting a block of memory and doing whatever you want inside it, instead you use things like object pools.


You can allocate a block of memory with `ByteBuffer.allocate()` or, if you want it outside the JVM heap, `ByteBuffer.allocateDirect()`.

You lose all the object/memory management features, though there are some projects around to provide struct-like APIs: https://github.com/alaisi/nalloc


System.Runtime.InteropServices.Marshal in C#'s case.


Also `fixed` in C# [1]

Not used Span<T> and Memory<T> [2] in anger yet, but they also seem to be attacking the issue from the other end

[1] https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...

[2] https://blogs.msdn.microsoft.com/mazhou/2018/03/25/c-7-serie...


I consider object pools to be well within that family of problem solving that I'm talking about.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: