-
Notifications
You must be signed in to change notification settings - Fork 62
Feature: Custom Memory Allocator #178
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
Feature: Custom Memory Allocator #178
Conversation
|
The size_t type is not a built-in keyword in C; it's defined in standard library headers like <stdlib.h>. Please, fix |
Updated the PR |
|
Hello @suhasravi7 . Thanks for the patch. I guess it is not as easy as I thought ... could you please merge next change to your branch and incorporate it to the PR to check if compilation errors are fixed? |
|
Hello @suhasravi7 : Could you please justify why this should be merged? We don't see a clear requirement to change memory allocators, and we find some security constraints on including it ... which architecture, software, product, ... justifies this change? CC @sergio-correia |
Thank you for raising these concerns @sarroutbi. The motivation for introducing a custom memory allocator support in JOSE stems from our deployment environment, where we utilize an H2O proxy(https://github.com/h2o/h2o). H2O internally pre-allocates and manages memory blocks to optimize performance and reduce allocation overhead, especially under high concurrency. To align with this architecture and fully leverage these performance benefits, we require JOSE to support custom memory allocators. By enabling JOSE to use externally managed allocators, we can maintain consistent memory management strategies across our stack. This approach offers measurable improvements in allocation speed and reduces fragmentation, compared to standard malloc/calloc routines. Additionally, it allows for tighter control over memory usage, which is critical in high-performance and resource-constrained environments. Regarding security, the implementation ensures that allocator hooks are strictly opt-in and can be sandboxed or audited according to deployment requirements. The change is modular and does not impact default behavior unless explicitly configured. |
|
should the api jose_cfg_set_alloc enforce consistency in the passed parameters. either all should be NULL or Non-NULL. a combination of NULL and Non Null paramters could lead to mis management of the allocated memory here? |
@vikaspushkar updated the pr to handle this case |
33598fb to
64f90d6
Compare
Thanks for clarifying. Changes LGTM. Let's wait for a double opinion regarding this and we can merge it |
sarroutbi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
64f90d6 to
dde2b04
Compare
simo5
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment, but I think this code can be made more compact and efficient.
5e19c34 to
31516cc
Compare
b571eb4 to
3b326f5
Compare
- Implement global function pointers for memory allocation - Add jose_set_alloc(), jose_get_alloc(), jose_reset_alloc() - Add comprehensive test suite in api_mem.c - Remove cfg dependencies from io.c structs - All tests passing (26/26)
simo5
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
Adds custom memory allocator support to the JOSE library, allowing applications to override default malloc/realloc/free functions for specialized memory management needs.
Changes
jose_set_alloc()andjose_get_alloc()API functionsapi_mem.c)Use Cases
Testing
meson test -C build api_memAll tests pass, validating functionality across different usage scenarios.