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

Function _memory_usable_size

vm/ByteCodeTranslator/src/rpmalloc.c:1235–1255  ·  view source on GitHub ↗

Get the usable size of the given block

Source from the content-addressed store, hash-verified

1233
1234//! Get the usable size of the given block
1235static size_t
1236_memory_usable_size(void* p) {
1237 //Grab the span (always at start of span, using 64KiB alignment)
1238 span_t* span = (void*)((uintptr_t)p & SPAN_MASK);
1239 int32_t heap_id = atomic_load32(&span->heap_id);
1240 if (heap_id) {
1241 if (span->size_class < SIZE_CLASS_COUNT) {
1242 //Small/medium block
1243 size_class_t* size_class = _memory_size_class + span->size_class;
1244 return size_class->size;
1245 }
1246
1247 //Large block
1248 size_t current_spans = (span->size_class - SIZE_CLASS_COUNT) + 1;
1249 return (current_spans * (size_t)SPAN_MAX_SIZE) - SPAN_HEADER_SIZE;
1250 }
1251
1252 //Oversized block, page count is stored in next_span
1253 size_t current_pages = (size_t)span->next_span;
1254 return (current_pages * (size_t)PAGE_SIZE) - SPAN_HEADER_SIZE;
1255}
1256
1257//! Adjust and optimize the size class properties for the given class
1258static void

Callers 1

rpmalloc_usable_sizeFunction · 0.85

Calls 1

atomic_load32Function · 0.85

Tested by

no test coverage detected