summaryrefslogtreecommitdiff
path: root/src/allocf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/allocf.c')
-rw-r--r--src/allocf.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/allocf.c b/src/allocf.c
index b5c7d4b..18555d9 100644
--- a/src/allocf.c
+++ b/src/allocf.c
@@ -6,16 +6,24 @@
#include <stdlib.h>
#include <mruby.h>
-/* This function serves as the default memory allocation function and accepts four arguments:
+/* This function serves as the default memory allocation function and accepts two arguments:
*
- * - `mrb`: An instance of `mrb_state`. It's important to note that for the initial allocation (used to allocate the `mrb_state` itself), `mrb` is set to NULL.
* - `p`: The previous pointer to the memory region. For memory allocation, this parameter is NULL.
- * - `size`: The new size of the memory region to be returned.
- * - `ud`: User data, represented as a `void*`, which is passed to the `mrb_state`.
+ * - `size`: The new size of the memory region to be returned. If size is 0, the memory region will be freed.
+ *
+ * All memory allocation from the inside of mruby uses this function.
+ *
+ * If you want to use your own memory allocator, you have two options:
+ *
+ * - provide your own version of malloc() / realloc() / free()
+ *
+ * - redefine mrb_basic_alloc_func() in your application.
+ *
+ * See doc/guides/memory.md for detail.
*/
void*
-mrb_default_allocf(mrb_state *mrb, void *p, size_t size, void *ud)
+mrb_basic_alloc_func(void *p, size_t size)
{
if (size == 0) {
/* `free(NULL)` should be no-op */
@@ -23,7 +31,7 @@ mrb_default_allocf(mrb_state *mrb, void *p, size_t size, void *ud)
return NULL;
}
else {
- /* `ralloc(NULL, size)` works as `malloc(size)` */
+ /* `realloc(NULL, size)` should work as `malloc(size)` */
return realloc(p, size);
}
}