MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / _memory_allocate

Function _memory_allocate

vm/ByteCodeTranslator/src/rpmalloc.c:1130–1148  ·  view source on GitHub ↗

Allocate a block of the given size

Source from the content-addressed store, hash-verified

1128
1129//! Allocate a block of the given size
1130static void*
1131_memory_allocate(size_t size) {
1132 if (size <= MEDIUM_SIZE_LIMIT)
1133 return _memory_allocate_from_heap(_memory_thread_heap, size);
1134 else if (size <= LARGE_SIZE_LIMIT)
1135 return _memory_allocate_large_from_heap(_memory_thread_heap, size);
1136
1137 //Oversized, allocate pages directly
1138 size += SPAN_HEADER_SIZE;
1139 size_t num_pages = size / PAGE_SIZE;
1140 if (size % PAGE_SIZE)
1141 ++num_pages;
1142 span_t* span = _memory_map(num_pages);
1143 atomic_store32(&span->heap_id, 0);
1144 //Store page count in next_span
1145 span->next_span = (span_t*)((uintptr_t)num_pages);
1146
1147 return pointer_offset(span, SPAN_HEADER_SIZE);
1148}
1149
1150//! Deallocate the given block
1151static void

Callers 3

_memory_reallocateFunction · 0.85
rpmallocFunction · 0.85
rpcallocFunction · 0.85

Calls 4

_memory_mapFunction · 0.85
atomic_store32Function · 0.85

Tested by

no test coverage detected