Skip to content
Compare
Choose a tag to compare

Beta 0.2

@ryanfleury ryanfleury released this
· 188 commits to master since this release
Compare
Choose a tag to compare

https://dion.systems/metadesk

Metadesk's second Beta version. Adds an arena allocator to provide control over allocations done by the library. Breaks the library's API. We strongly recommend that you upgrade to this version to avoid more breakage later.

Before this version, the library would "malloc and forget", with the assumption that the user would never free. This is generally true in metaprograms that start, do parsing + generation, and terminate. However, in more complex metaprograms or in applications that use Metadesk in another way - for example, a GUI application with user interaction that could last for an undetermined amount of time - it is desirable to have control over when and where the library allocates, and how to free the memory it allocates.

The API has changed in this version in order to bind all allocations to arena allocators. These function like handles that bundle memory allocations. Then, to free anything allocated with an arena, the user can release or clear the arena. The arena implementation is overridable with a custom implementation.

Now, any function that does allocation will take an MD_Arena * parameter.

To upgrade from Beta 0.1 to Beta 0.2 without breaking any of your code, you'll want to allocate everything with a single global arena.

To do this, declare an arena:

static MD_Arena *arena = 0;

Initialize the arena with a very large upper-limit:

arena = MD_ArenaAlloc(1 << 30);

And pass arena where appropriate:

// Before Beta 0.2:
MD_String8List list = MD_S8Split(string, split_count, splits); // <-- breaks with new API

// Beta 0.2:
MD_String8List list = MD_S8Split(arena, string, split_count, splits);

Once you've converged on all of the APIs, your code should work the same as it did before.