Normalize how the global heap pool is configured across iwasm apps (#1628)
Use the cmake variable `WAMR_BUILD_GLOBAL_HEAP_POOL` and `WAMR_BUILD_GLOBAL_HEAP_SIZE` to enable/disable the global heap pool and set its size. And set the default global heap size in core/config.h and the cmake files. As a result, the developers who build iwasm can easily enable/disable the global heap pool and change its size regardless of the iwasm implementation, without manually finding and patching the right location for that value.
This commit is contained in:
@ -45,6 +45,11 @@ if (NOT DEFINED WAMR_ROOT_DIR)
|
||||
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endif ()
|
||||
|
||||
# Override the global heap size for small devices
|
||||
if (NOT DEFINED WAMR_BUILD_GLOBAL_HEAP_SIZE)
|
||||
add_definitions (-DWASM_GLOBAL_HEAP_SIZE=262144) # 256 kB
|
||||
endif ()
|
||||
|
||||
|
||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
|
||||
|
||||
@ -55,9 +55,8 @@ iwasm_t(void *arg1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* choose allocator */
|
||||
/* enable FUNC_ALLOC to use custom memory allocation functions */
|
||||
#define FUNC_ALLOC
|
||||
/* #define POOL_ALLOC */
|
||||
|
||||
void *
|
||||
iwasm_main(void *arg1)
|
||||
@ -71,17 +70,17 @@ iwasm_main(void *arg1)
|
||||
RuntimeInitArgs init_args;
|
||||
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
#ifdef POOL_ALLOC
|
||||
static char global_heap_buf[256 * 1024] = { 0 }; /* 256 kB */
|
||||
|
||||
init_args.mem_alloc_type = Alloc_With_Pool;
|
||||
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
|
||||
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
|
||||
#elif defined(FUNC_ALLOC)
|
||||
#if defined(FUNC_ALLOC) && WASM_ENABLE_GLOBAL_HEAP_POOL == 0
|
||||
init_args.mem_alloc_type = Alloc_With_Allocator;
|
||||
init_args.mem_alloc_option.allocator.malloc_func = malloc;
|
||||
init_args.mem_alloc_option.allocator.realloc_func = realloc;
|
||||
init_args.mem_alloc_option.allocator.free_func = free;
|
||||
#elif WASM_ENABLE_GLOBAL_HEAP_POOL != 0
|
||||
static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 };
|
||||
|
||||
init_args.mem_alloc_type = Alloc_With_Pool;
|
||||
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
|
||||
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
|
||||
#else
|
||||
init_args.mem_alloc_type = Alloc_With_System_Allocator;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user