drmelon

all chosters chost chosts

gamedev (snolf romhack) πŸ‰ music πŸ‰ interactive fiction πŸ‰ pyjama elemental πŸ‰ nonbinary pan πŸ‰ πŸ’œ @leafcodes

@drmelon@mastodon.gamedev.place


eniko
@eniko

i'll talk about this more if people care (plz leave a comment if so) but, i made a proof of concept for arena allocators in C# that work nicely with managed C#. basically, you can have a chunk of unmanaged memory, toss structs in there, and then free everything in the arena all at once, like clearing all memory associated with a level after exiting it. this is useful because unmanaged memory doesn't add GC pressure. also the structs can have references to managed C# objects. here's what using it looks like:

UnmanagedRef<Entity> entity;

using (var arena = new Arena()) {
    entity = arena.Allocate(new Entity(1, 2, 3));
    entity.Value->Name = "John Doe";
    entity.Value->Y = 8;
    Console.WriteLine(entity);

    entity.Free();
}

entity.Free();
Console.WriteLine($"Is entity.Value null? {entity.Value == null}");

eniko
@eniko

i think this experiment is basically done, so if there was ever a time to give it a look, now's the time. arena allocators allow you to allocate and use unmanaged memory in chunks and free all of it in one go, and since it's unmanaged it adds no GC pressure

think of stuff like per-level storage (dump everything on level exit) or a per-frame arena for things items that only ever live for one frame

might turn this into a proper library if anyone actually cares



You must log in to comment.