Lines Matching refs:size
35 static size_t round_blocksize(size_t size) in round_blocksize() argument
37 if (size < 256) in round_blocksize()
39 return size; in round_blocksize()
43 return (size + 1023) / 1024 * 1024; in round_blocksize()
47 static size_t round_blocksize(size_t size) in round_blocksize() argument
49 return size; in round_blocksize()
54 void* malloc_with_check(size_t size) in malloc_with_check() argument
58 if (size <= g_max_alloc_bytes - g_alloc_bytes) in malloc_with_check()
60 buf = malloc(round_blocksize(size + GUARD_SIZE)); in malloc_with_check()
65 ((size_t*)buf)[0] = size; in malloc_with_check()
67 ((size_t*)(buf + size))[2] = CHECK2; in malloc_with_check()
69 g_alloc_bytes += size; in malloc_with_check()
70 …OC) fprintf(stderr, "Alloc 0x%04x/%u\n", (unsigned)(uintptr_t)(buf + PREFIX_SIZE), (unsigned)size); in malloc_with_check()
75 if (DEBUG_MALLOC) fprintf(stderr, "malloc(%u) failed\n", (unsigned)size); in malloc_with_check()
86 size_t size = ((size_t*)buf)[0]; in free_with_check() local
87 …if (DEBUG_MALLOC) fprintf(stderr, "Release 0x%04x/%u\n", (unsigned)(uintptr_t)mem, (unsigned)size); in free_with_check()
89 assert(((size_t*)(buf + size))[2] == CHECK2); in free_with_check()
91 assert(g_alloc_bytes >= size); in free_with_check()
93 ((size_t*)(buf + size))[2] = 0; in free_with_check()
95 g_alloc_bytes -= size; in free_with_check()
101 void* realloc_with_check(void *ptr, size_t size) in realloc_with_check() argument
103 if (!ptr && size) in realloc_with_check()
106 return malloc_with_check(size); in realloc_with_check()
108 else if (ptr && size) in realloc_with_check()
118 if (size <= g_max_alloc_bytes - (g_alloc_bytes - oldsize)) in realloc_with_check()
120 size_t new_rounded = round_blocksize(size + GUARD_SIZE); in realloc_with_check()
135 …, "Realloc 0x%04x/%u to %u failed\n", (unsigned)(uintptr_t)ptr, (unsigned)oldsize, (unsigned)size); in realloc_with_check()
139 ((size_t*)buf)[0] = size; in realloc_with_check()
141 ((size_t*)(buf + size))[2] = CHECK2; in realloc_with_check()
143 g_alloc_bytes += size; in realloc_with_check()
145 …igned)(uintptr_t)ptr, (unsigned)oldsize, (unsigned)(uintptr_t)(buf + PREFIX_SIZE), (unsigned)size); in realloc_with_check()
148 else if (ptr && !size) in realloc_with_check()