Skip to content

Zig libraries need to manage their own memory #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mnemnion opened this issue Jul 3, 2024 · 1 comment
Closed

Zig libraries need to manage their own memory #22

mnemnion opened this issue Jul 3, 2024 · 1 comment

Comments

@mnemnion
Copy link
Contributor

mnemnion commented Jul 3, 2024

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...

@Techatrix
Copy link
Member

fixed by #23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants