Memory management with Zero stdlib?
orthoxerox opened this issue · comments
Since Zero has no GC, how do I deallocate the memory I no longer need?
Since Zero has no GC, how do I deallocate the memory I no longer need?
That's the neat part, you don't.
I typically avoid allocating any memory when using zerolib, or only do it at startup. Makes things more interesting.
Pretend you are using C, and call HeapAlloc/HeapFree on raw pointers.
Any code examples on that topic? There is multiple ways to work with pointers in C#.
I'd also really appreciate any example showing new class allocation, when not using any runtime.
Currently, I've got a very basic Console
class I'm trying to instantiate:
unsafe class Program
{
static int Main()
{
Console console;
console = new Console();
Which throws the following error upon linking (nb. I'm using the GNU linker, ld
but I've also got similar working with the Microsoft linker, link
):
RhpNewFast
seems to refer to any internal runtime call to new up an object, circa: https://github.com/dotnet/corert/blob/9d8bd29a71f68941aaa2c00e9c9a0eed86cafa10/src/Runtime.Base/src/System/Runtime/RuntimeExports.cs#L28-L61
Interestingly, the above linking (and running) works fine if I convert the Console class to be fully static, and call it so.
Any pointers how to begin?
(ps. I want to be able to create instance classes, not just statics, as ultimately I want to be able to utilise Console in a unit test project elsewhere)
UPDATE: From MOOS, this looks interesting: private static unsafe object RhpNewFast(EEType* pEEType)
UPDATE 2: A custom allocator for managed .Net, perhaps closer to what's needed: Custom memory allocation in C# Part 3