mirror of
https://github.com/dlang/phobos.git
synced 2025-05-11 23:05:34 +03:00
Merge pull request #5781 from edi33416/bucketizer_fix
Fix bucketizer aligned allocate merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
This commit is contained in:
commit
58a987ae5f
1 changed files with 5 additions and 4 deletions
|
@ -69,18 +69,19 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step)
|
|||
}
|
||||
|
||||
/**
|
||||
Allocates the requested `bytes` of memory with specified `alignment`.
|
||||
Directs the call to either one of the $(D buckets) allocators. Defined only
|
||||
if `Allocator` defines `alignedAllocate`.
|
||||
*/
|
||||
static if (hasMember!(Allocator, "alignedAllocate"))
|
||||
void[] alignedAllocate(size_t bytes, uint a)
|
||||
void[] alignedAllocate(size_t bytes, uint alignment)
|
||||
{
|
||||
if (!bytes) return null;
|
||||
if (auto a = allocatorFor(b.length))
|
||||
if (auto a = allocatorFor(bytes))
|
||||
{
|
||||
const actual = goodAllocSize(bytes);
|
||||
auto result = a.alignedAllocate(actual);
|
||||
return result.ptr ? result.ptr[0 .. bytes] : null;
|
||||
auto result = a.alignedAllocate(actual, alignment);
|
||||
return result !is null ? (() @trusted => (&result)[0 .. bytes])() : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue