35 #if MICROPY_DEBUG_VERBOSE // print debugging info 36 #define DEBUG_printf DEBUG_printf 37 #else // don't print debugging info 38 #define DEBUG_printf(...) (void)0 42 #define UPDATE_PEAK() { if (MP_STATE_MEM(current_bytes_allocated) > MP_STATE_MEM(peak_bytes_allocated)) MP_STATE_MEM(peak_bytes_allocated) = MP_STATE_MEM(current_bytes_allocated); } 56 #define malloc(b) gc_alloc((b), false) 57 #define malloc_with_finaliser(b) gc_alloc((b), true) 59 #define realloc(ptr, n) gc_realloc(ptr, n, true) 60 #define realloc_ext(ptr, n, mv) gc_realloc(ptr, n, mv) 72 #endif // MICROPY_ENABLE_GC 75 void *ptr =
malloc(num_bytes);
76 if (ptr ==
NULL && num_bytes != 0) {
89 void *ptr =
malloc(num_bytes);
99 #if MICROPY_ENABLE_FINALISER 101 void *ptr = malloc_with_finaliser(num_bytes);
102 if (ptr ==
NULL && num_bytes != 0) {
105 #if MICROPY_MEM_STATS 117 if (ptr ==
NULL && num_bytes != 0) {
121 #if !MICROPY_GC_CONSERVATIVE_CLEAR 122 memset(ptr, 0, num_bytes);
127 #if MICROPY_MALLOC_USES_ALLOCATED_SIZE 128 void *
m_realloc(
void *ptr,
size_t old_num_bytes,
size_t new_num_bytes) {
132 void *new_ptr =
realloc(ptr, new_num_bytes);
133 if (new_ptr ==
NULL && new_num_bytes != 0) {
136 #if MICROPY_MEM_STATS 142 size_t diff = new_num_bytes - old_num_bytes;
147 DEBUG_printf(
"realloc %p, %d, %d : %p\n", ptr, old_num_bytes, new_num_bytes, new_ptr);
151 #if MICROPY_MALLOC_USES_ALLOCATED_SIZE 152 void *
m_realloc_maybe(
void *ptr,
size_t old_num_bytes,
size_t new_num_bytes,
bool allow_move) {
156 void *new_ptr =
realloc_ext(ptr, new_num_bytes, allow_move);
157 #if MICROPY_MEM_STATS 164 if (!(new_ptr ==
NULL && new_num_bytes != 0)) {
165 size_t diff = new_num_bytes - old_num_bytes;
171 DEBUG_printf(
"realloc %p, %d, %d : %p\n", ptr, old_num_bytes, new_num_bytes, new_ptr);
175 #if MICROPY_MALLOC_USES_ALLOCATED_SIZE 176 void m_free(
void *ptr,
size_t num_bytes) {
181 #if MICROPY_MEM_STATS 187 #if MICROPY_MEM_STATS 188 size_t m_get_total_bytes_allocated(
void) {
192 size_t m_get_current_bytes_allocated(
void) {
196 size_t m_get_peak_bytes_allocated(
void) {
void * memset(void *b, int c, size_t len)
void * malloc(size_t size)
STATIC void * realloc_ext(void *ptr, size_t n_bytes, bool allow_move)
void * m_realloc(void *ptr, size_t new_num_bytes)
void * m_malloc_with_finaliser(size_t num_bytes)
#define DEBUG_printf(...)
void * m_realloc_maybe(void *ptr, size_t new_num_bytes, bool allow_move)
void * realloc(void *ptr, size_t size)
void * m_malloc0(size_t num_bytes)
NORETURN void m_malloc_fail(size_t num_bytes)
void * m_malloc(size_t num_bytes)
void * m_malloc_maybe(size_t num_bytes)