mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-08 20:56:13 +00:00
Add a new API to get free memory in memory pool (#1430)
This commit is contained in:
parent
e0c2acd178
commit
77c516ac80
|
@ -167,3 +167,12 @@ wasm_runtime_free(void *ptr)
|
|||
{
|
||||
wasm_runtime_free_internal(ptr);
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info)
|
||||
{
|
||||
if (memory_mode == MEMORY_MODE_POOL) {
|
||||
return mem_allocator_get_alloc_info(pool_allocator, mem_alloc_info);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -121,6 +121,13 @@ typedef union MemAllocOption {
|
|||
} MemAllocOption;
|
||||
#endif
|
||||
|
||||
/* Memory pool info */
|
||||
typedef struct mem_alloc_info_t {
|
||||
uint32_t total_size;
|
||||
uint32_t total_free_size;
|
||||
uint32_t highmark_size;
|
||||
} mem_alloc_info_t;
|
||||
|
||||
/* WASM runtime initialize arguments */
|
||||
typedef struct RuntimeInitArgs {
|
||||
mem_alloc_type_t mem_alloc_type;
|
||||
|
@ -229,6 +236,12 @@ wasm_runtime_realloc(void *ptr, unsigned int size);
|
|||
WASM_RUNTIME_API_EXTERN void
|
||||
wasm_runtime_free(void *ptr);
|
||||
|
||||
/*
|
||||
* Get memory info, only pool mode is supported now.
|
||||
*/
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info);
|
||||
|
||||
/**
|
||||
* Get the package type of a buffer.
|
||||
*
|
||||
|
|
|
@ -69,6 +69,13 @@ mem_allocator_is_heap_corrupted(mem_allocator_t allocator)
|
|||
return gc_is_heap_corrupted((gc_handle_t)allocator);
|
||||
}
|
||||
|
||||
bool
|
||||
mem_allocator_get_alloc_info(mem_allocator_t allocator, void *mem_alloc_info)
|
||||
{
|
||||
gc_heap_stats((gc_handle_t)allocator, mem_alloc_info, 3);
|
||||
return true;
|
||||
}
|
||||
|
||||
#else /* else of DEFAULT_MEM_ALLOCATOR */
|
||||
|
||||
#include "tlsf/tlsf.h"
|
||||
|
|
|
@ -45,6 +45,9 @@ mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new,
|
|||
bool
|
||||
mem_allocator_is_heap_corrupted(mem_allocator_t allocator);
|
||||
|
||||
bool
|
||||
mem_allocator_get_alloc_info(mem_allocator_t allocator, void *mem_alloc_info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user