TempAlloc review starts now
Lutger Blijdestijn
lutger.blijdestijn at gmail.com
Mon Jun 6 14:27:44 PDT 2011
dsimcha wrote:
> == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
>> alignedMalloc:
>> I seriously question having such a feature. According to my C++ book
>> malloc returns a pointer "suitably aligned for any type". According to
>> Microsoft, malloc is 16-byte aligned (of course, D doesn't use
>> microsoft's
>> runtime, DMC doesn't seem to identify alignment in malloc docs). GNU
>> appears to guarantee 8-byte alignment on 32-bit systems, 16 on 64-bit
>> systems (making this function mostly useless on 64-bit dmd).
>> There are also some posix functions that align a malloc to a requested
>> size (see memalign).
>
> I definitely need it in the implementation of TempAlloc, so it's gonna be
> there but it can be made private if there's a consensus that it's not
> needed in the public API.
>
>> At the very least, the function should identify what the alignment is if
>> you *don't* use it. I'd like to see a good use case for this feature in
>> an example, otherwise, I think it should be killed.
>
> The alignment if you don't use it depends on the C malloc function for
> your
> platform. A use case might be if you need 16-byte aligned arrays to use
> SSE instructions, but that's hard to demonstrate in a short example.
Maybe it would be more broadly useful if the alignment could be specified,
turning it into a portable version of posix_memalign?
http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_memalign.html
It's not my domain and use cases may be niche, but it does fit the systems
language aspect of D.
More information about the Digitalmars-d
mailing list