-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
zflecs: fix wrong alignment issue #303
Conversation
Thanks for the PR! So, this adds 128 bytes to each allocation, right? This seems expensive to me. In other libs I use a hash map to track size and alignment for each allocation. Like here: So my approach adds 8 bytes per allocation + some hash map lookups. I think this PR is good idea but I would prefer to use approach with the hash map. What do you think? Would you like to modify this PR? |
Oh sorry. I mixed bits/bytes up in this pull request. The max alignment should be 16 bytes not 128 lol. Do you think 16 bytes of extra space for the allocation header is fine or should we use a hashmap anyways? |
Maybe we could use 8 bytes for a header and store there size ( |
That would also mean that the maximum alignment that flecs would be able to request is 8 bytes. Glibc malloc seems to align to 16 bytes on 64bit platforms by default. I guess we can expose the alignment as a build_option in case you have a component that requires a greater alignment. |
I thought that Let's go with 16 bytes headers. |
…ent exceeds the one that the EcsAllocator provides
Should be good now. Let me know if you would like me to change something. |
451f959
to
138bef3
Compare
# Conflicts: # libs/zflecs/src/zflecs.zig
This is the flecs issue for reference.
Compiling flecs using
-DFLECS_USE_OS_ALLOC
already works around the issue.But I've also implemented the allocation related os calls using a gpa to track memory leaks and guarantee correct alignment.
I haven't benchmarked the performance impact of using it. So it might make sense to make it optional 🤷.
This change should fix #284.