MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / _rpmalloc_usable_size

Function _rpmalloc_usable_size

source/extern/rpmalloc.c:2715–2732  ·  view source on GitHub ↗

Get the usable size of the given block

Source from the content-addressed store, hash-verified

2713
2714//! Get the usable size of the given block
2715static size_t
2716_rpmalloc_usable_size(void* p) {
2717 //Grab the span using guaranteed span alignment
2718 span_t* span = (span_t*)((uintptr_t)p & _memory_span_mask);
2719 if (span->size_class < SIZE_CLASS_COUNT) {
2720 //Small/medium block
2721 void* blocks_start = pointer_offset(span, SPAN_HEADER_SIZE);
2722 return span->block_size - ((size_t)pointer_diff(p, blocks_start) % span->block_size);
2723 }
2724 if (span->size_class == SIZE_CLASS_LARGE) {
2725 //Large block
2726 size_t current_spans = span->span_count;
2727 return (current_spans * _memory_span_size) - (size_t)pointer_diff(p, span);
2728 }
2729 //Oversized block, page count is stored in span_count
2730 size_t current_pages = span->span_count;
2731 return (current_pages * _memory_page_size) - (size_t)pointer_diff(p, span);
2732}
2733
2734//! Adjust and optimize the size class properties for the given class
2735static void

Callers 2

rpmalloc_usable_sizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected