MtFmt 1.0.0
MtFmt is a format library on embed. system and wrote by pure C.
载入中...
搜索中...
未找到
mm_heap.h
浏览该文件的文档.
1// SPDX-License-Identifier: LGPL-3.0
12#if !defined(_INCLUDE_MM_HEAP_H_)
13#define _INCLUDE_MM_HEAP_H_ 1
14#include "mm_cfg.h"
15#include "mm_type.h"
16
24mstr_heap_init_sym(iptr_t heap_memory, usize_t heap_size);
25
31MSTR_EXPORT_API(void*)
33
43MSTR_EXPORT_API(void*)
45 void* old_ptr, usize_t new_size, usize_t old_size
46);
47
52MSTR_EXPORT_API(void) mstr_heap_free_sym(void* memory);
53
58MSTR_EXPORT_API(usize_t) mstr_heap_get_free_size(void);
59
64MSTR_EXPORT_API(usize_t) mstr_heap_get_high_water_mark(void);
65
71MSTR_EXPORT_API(void*)
73 void* old_ptr, usize_t new_size, usize_t old_size
74);
75
83mstr_heap_get_allocate_count(usize_t* alloc_count, usize_t* free_count);
84
85#if _MSTR_USE_MALLOC
86#define mstr_heap_init(mem, leng) ((void)mem, (void)leng)
87
88#define mstr_heap_alloc(s) _MSTR_MEM_ALLOC_FUNCTION((s))
89
90#if MSTR_MEM_REALLOC_FUNCTION_NOT_AVAL
95#define mstr_heap_realloc(p, new_s, old_s) \
96 mstr_heap_realloc_cpimp_sym((p), (new_s), (old_s))
97#else
102#define mstr_heap_realloc(p, s, os) _MSTR_MEM_REALLOC_FUNCTION((p), (s))
103#endif // MSTR_MEM_REALLOC_FUNCTION_NOT_AVAL
104
105#define mstr_heap_free(m) \
106 do { \
107 _MSTR_MEM_FREE_FUNCTION(m); \
108 (m) = NULL; \
109 } while (0)
110#else
111#define mstr_heap_init(mem, leng) \
112 do { \
113 mstr_heap_init_sym((iptr_t)(mem), (usize_t)(leng)); \
114 } while (0)
115
116#define mstr_heap_alloc(s) (mstr_heap_allocate_sym((s), 4))
117
118#define mstr_heap_realloc(p, new_s, old_s) \
119 mstr_heap_re_allocate_sym((p), (new_s), (old_s))
120
121#define mstr_heap_free(m) \
122 do { \
123 mstr_heap_free_sym(m); \
124 (m) = NULL; \
125 } while (0)
126
127#endif // _MSTR_USE_MALLOC
128
129#endif // _INCLUDE_MU_HEAP_H_
配置选项
mstr_heap_allocate_sym(usize_t size, usize_t align)
尝试从堆中分配size大小的内存
Definition mm_heap.c:127
mstr_heap_re_allocate_sym(void *old_ptr, usize_t new_size, usize_t old_size)
尝试从堆中重新分配size大小的内存
Definition mm_heap.c:135
mstr_heap_get_allocate_count(usize_t *alloc_count, usize_t *free_count)
取得分配器的统计数据
Definition mm_heap.c:163
MSTR_EXPORT_API(void) mstr_heap_free_sym(void *memory)
释放由 mstr_heap_allocate 分配的内存
Definition mm_heap.c:147
mstr_heap_realloc_cpimp_sym(void *old_ptr, usize_t new_size, usize_t old_size)
由memcpy实现realloc
Definition mm_heap.c:170
mstr_heap_init_sym(iptr_t heap_memory, usize_t heap_size)
初始化堆分配器
Definition mm_heap.c:121
type alias和type def
intptr_t iptr_t
Definition mm_type.h:39
size_t usize_t
尺寸(无符号)
Definition mm_type.h:32