Skip to content

Zig libraries need to manage their own memory #22

Closed
@mnemnion

Description

@mnemnion

I was looking for a diffing library to use on a Zig project, and diffz looked like the best candidate. Even with just the diffing portion of diff-match-patch, and a lack of recent commits (it happens), I figured hey, community-supported library, it's got the part I actually need, and maybe I could take some time to continue the port.

I was disappointed to see that the library uses an arena as though it were a garbage collector. In a ziglib, functions are expected to take a generic Allocator, and behave accordingly, by freeing any memory they don't return. If the user wants to use an ArenaAllocator, that's fine, free is a no-op unless the allocation happens to be the last one performed, so one ends up with the performance benefits, while maintaining the flexibility which is a core competency of the language.

I assume this unfortunate state of affairs came to be because this version of diff-match-patch is a port from a garbage collected language, C♯ presumably. It's just a pity, because Zig provides such excellent tools for finding memory leaks, use after free, and double free, and the library has a robust test suite. Proper memory management could have been added during the port, and then this would be a real Zig library, not just a promising sketch of one.

Anyway, now there's an issue to track this, in case anyone wants to close it...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions