MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / _mi_segment_of

Function _mi_segment_of

3rd/mimalloc-2.0.9/src/segment-cache.c:327–337  ·  view source on GitHub ↗

Determine the segment belonging to a pointer or NULL if it is not in a valid segment.

Source from the content-addressed store, hash-verified

325
326// Determine the segment belonging to a pointer or NULL if it is not in a valid segment.
327static mi_segment_t* _mi_segment_of(const void* p) {
328 if (p == NULL) return NULL;
329 mi_segment_t* segment = _mi_ptr_segment(p);
330 mi_assert_internal(segment != NULL);
331 size_t bitidx;
332 size_t index = mi_segment_map_index_of(segment, &bitidx);
333 // fast path: for any pointer to valid small/medium/large object or first MI_SEGMENT_SIZE in huge
334 const uintptr_t mask = mi_atomic_load_relaxed(&mi_segment_map[index]);
335 if mi_likely((mask & ((uintptr_t)1 << bitidx)) != 0) {
336 return segment; // yes, allocated by us
337 }
338 if (index==MI_SEGMENT_MAP_WSIZE) return NULL;
339
340 // TODO: maintain max/min allocated range for efficiency for more efficient rejection of invalid pointers?

Callers 1

mi_is_valid_pointerFunction · 0.85

Calls 2

_mi_ptr_segmentFunction · 0.85
mi_segment_map_index_ofFunction · 0.85

Tested by

no test coverage detected