3 ms·
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
by gameswithgo 8y ago
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.
- pjmlp 8y agoSystem.Runtime.InteropServices.Marshal in C#'s case.
- louthy 8y agoAlso `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-reference/keywords/fixed-statement https://docs.microsoft.com/en-us/dotnet/csharp/language-refe... [2] https://blogs.msdn.microsoft.com/mazhou/2018/03/25/c-7-series-part-10-spant-and-universal-memory-management/ https://blogs.msdn.microsoft.com/mazhou/2018/03/25/c-7-serie...
- VikingCoder 8y agoI consider object pools to be well within that family of problem solving that I'm talking about.
- jakewins 8y agoYou 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 https://github.com/alaisi/nalloc