std.allocator ready for some abuse

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 27 11:36:11 PDT 2013


On 10/27/13 11:26 AM, safety0ff wrote:
> On Sunday, 27 October 2013 at 10:45:31 UTC, Andrei Alexandrescu wrote:
>> On 10/26/13 8:00 AM, Andrei Alexandrescu wrote:
>>> AlignedMallocator that uses the _aligned_* family on Windows and the
>>> respective functions on Posix. On Windows, allocate() requests would
>>> pass a default of platformSize (i.e. 16 I suspect) to _aligned_malloc.
>>
>> Just implemented AlignedMallocator and pushed.
>>
>> http://erdani.com/d/phobos-prerelease/std_allocator.html#.AlignedMallocator
>>
> The constraints on the alignment parameter are neither documented nor
> checked.
>
> i.e. Alignment must be a power of two, and for posix_memalign it must
> additionally be greater than sizeof(void*).

Fixed, will push soon.

> I can only think of one use case for needing runtime specified
> alignment: allocating operating system page sized chunks.
> Are there any other use cases?

Cache-line aligned.

http://stackoverflow.com/questions/794632/programmatically-get-the-cache-line-size/1900464

Also some I/O requires aligned buffers.

http://goo.gl/ni860U


Andrei



More information about the Digitalmars-d mailing list