Get the usable size of the given block
| 1233 | |
| 1234 | //! Get the usable size of the given block |
| 1235 | static 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 |
| 1258 | static void |
no test coverage detected