mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-05 15:09:31 +03:00
Merge pull request #220 from cormacrelf/usable_size
Don't call mi_page_usable_size_of with an aligned pointer
This commit is contained in:
commit
1ece3ff6aa
2 changed files with 8 additions and 4 deletions
|
@ -477,15 +477,16 @@ size_t mi_usable_size(const void* p) mi_attr_noexcept {
|
||||||
if (p==NULL) return 0;
|
if (p==NULL) return 0;
|
||||||
const mi_segment_t* const segment = _mi_ptr_segment(p);
|
const mi_segment_t* const segment = _mi_ptr_segment(p);
|
||||||
const mi_page_t* const page = _mi_segment_page_of(segment, p);
|
const mi_page_t* const page = _mi_segment_page_of(segment, p);
|
||||||
const mi_block_t* const block = (const mi_block_t*)p;
|
const mi_block_t* block = (const mi_block_t*)p;
|
||||||
const size_t size = mi_page_usable_size_of(page, block);
|
|
||||||
if (mi_unlikely(mi_page_has_aligned(page))) {
|
if (mi_unlikely(mi_page_has_aligned(page))) {
|
||||||
ptrdiff_t const adjust = (uint8_t*)p - (uint8_t*)_mi_page_ptr_unalign(segment,page,p);
|
block = _mi_page_ptr_unalign(segment, page, p);
|
||||||
|
size_t size = mi_page_usable_size_of(page, block);
|
||||||
|
ptrdiff_t const adjust = (uint8_t*)p - (uint8_t*)block;
|
||||||
mi_assert_internal(adjust >= 0 && (size_t)adjust <= size);
|
mi_assert_internal(adjust >= 0 && (size_t)adjust <= size);
|
||||||
return (size - adjust);
|
return (size - adjust);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return size;
|
return mi_page_usable_size_of(page, block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,9 @@ int main() {
|
||||||
}
|
}
|
||||||
result = ok;
|
result = ok;
|
||||||
});
|
});
|
||||||
|
CHECK_BODY("malloc-aligned5", {
|
||||||
|
void* p = mi_malloc_aligned(4097,4096); size_t usable = mi_usable_size(p); result = usable >= 4097 && usable < 10000; mi_free(p);
|
||||||
|
});
|
||||||
CHECK_BODY("malloc-aligned-at1", {
|
CHECK_BODY("malloc-aligned-at1", {
|
||||||
void* p = mi_malloc_aligned_at(48,32,0); result = (p != NULL && ((uintptr_t)(p) + 0) % 32 == 0); mi_free(p);
|
void* p = mi_malloc_aligned_at(48,32,0); result = (p != NULL && ((uintptr_t)(p) + 0) % 32 == 0); mi_free(p);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue