From 7e4810658e289b6b7ae0a665724e0f9952ba6ca4 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 10 May 2025 09:07:35 +0900 Subject: [PATCH] allocf.c: update and enhance documentation in the comment --- src/allocf.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/allocf.c b/src/allocf.c index 2f0971898..18555d937 100644 --- a/src/allocf.c +++ b/src/allocf.c @@ -9,7 +9,17 @@ /* This function serves as the default memory allocation function and accepts two arguments: * * - `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. + * - `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* @@ -21,7 +31,7 @@ mrb_basic_alloc_func(void *p, size_t size) return NULL; } else { - /* `ralloc(NULL, size)` works as `malloc(size)` */ + /* `realloc(NULL, size)` should work as `malloc(size)` */ return realloc(p, size); } }