mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-07 11:58:41 +03:00
limit aligned allocation to power-of-two alignment
This commit is contained in:
parent
050e7cedf4
commit
24777f6a91
4 changed files with 26 additions and 18 deletions
|
@ -71,7 +71,8 @@ void* mi_pvalloc(size_t size) mi_attr_noexcept {
|
|||
}
|
||||
|
||||
void* mi_aligned_alloc(size_t alignment, size_t size) mi_attr_noexcept {
|
||||
if (alignment != 0 && (size%alignment) != 0) return NULL; // C11 required; <https://en.cppreference.com/w/c/memory/aligned_alloc>
|
||||
if (alignment==0 || !_mi_is_power_of_two(alignment)) return NULL;
|
||||
if ((size&(alignment-1)) != 0) return NULL; // C11 requires integral multiple, see <https://en.cppreference.com/w/c/memory/aligned_alloc>
|
||||
return mi_malloc_aligned(size, alignment);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue