Get the usable size of the given block
| 2713 | |
| 2714 | //! Get the usable size of the given block |
| 2715 | static 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 |
| 2735 | static void |
no outgoing calls
no test coverage detected