On Sunday, 27 October 2013 at 16:19:28 UTC, Peter Alexander wrote:
"The malloc() and calloc() functions return a pointer to the allocated memory that is suitably aligned for any kind of variable."

I see no reason to diverge from that.

Welö, except for the fact that "any kind of variable" is not well-defined for a language that supports user-defined alignment restrictions:

---
struct Foo {
    align(8192) byte b;
}

template Seq(T...) { alias Seq = T; }
void main() {
    import core.memory, core.stdc.stdio, core.stdc.stdlib;
    foreach (alloc; Seq!(malloc, GC.malloc)) {
        auto mem = cast(Foo*)alloc(Foo.sizeof);
printf("%u\n", cast(uint)(cast(size_t)mem & (Foo.alignof - 1)));
    }
}

---

David

Reply via email to