-
Notifications
You must be signed in to change notification settings - Fork 682
Make all dynamic memory allocations via core API functions in jerry-ext #4480
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
Make all dynamic memory allocations via core API functions in jerry-ext #4480
Conversation
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
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
JerryX should not rely on any internal things. That is a key design principle. |
@zherczeg jerry-ext should not rely on any internal functions, true. But BTW, jerry-ext/debugger is already using |
Direct calls to `malloc` and `free` should be avoided, `jerry_heap_alloc` and `jerry_heap_free` should be used in their place. Build-time configuration should decide whether those calls manage dynamic memory on the engine's heap or on the system heap. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
ab1e7a5
to
1eb56d3
Compare
True, I forgot these functions are exported. In general, what is the gain here? Jerry allocator is better than the system allocator, or we don't expect to have enough memory provided by the system? I would prefer allocating everything with malloc outside of JerryScript. |
Well, "outside" JerryScript, i.e., an embedder application does whatever it want. It knows very well what the platform allows or disallows. It knows whether using system allocator is OK or not. But the engine was designed to be able to run on systems where the system allocator must not be used for dynamic memory allocation (that's why it has its own heap, if configured so, and its own memory allocators). But jerry-ext is kind of a grey zone. It is not the core of the engine, it must not use internal routines, but it shall be "universal". Wherever the engine can work, the extensions should work, too (there may be some exception to that, but they should be the exceptions, not the rule). Therefore, if an extension needs dynamic memory, it should allocate that via the |
Would it be a good idea to make this configurable (jerry-ext can or cannot use malloc)? So people could choose the best for them. The default can be not to use it. |
jerryx_heap_free and jerryx_heap_malloc |
@zherczeg I'd keep configuration options to a minimum. Especially in this case. At least, for now. Adding that configurability would also mean adding a new memory management layer, even if thin. Something like Whether that should be implemented, I'd leave for a follow-up feature implementation PR (not by me). |
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
Direct calls to
malloc
andfree
should be avoided,jerry_heap_alloc
andjerry_heap_free
should be used in theirplace. Build-time configuration should decide whether those calls
manage dynamic memory on the engine's heap or on the system heap.
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu