Thread overview | |||||
---|---|---|---|---|---|
|
September 07, 2013 std.typecons scoped question | ||||
---|---|---|---|---|
| ||||
What is the reason behind the wasted memory when using the scoped template from std.typecons? For example class A { } class B { typeof(scoped!A()) a; this() { a = scoped!A(); } } void main(string[] args) { writeln("Size of class A: ", __traits(classInstanceSize, A)); writeln("Size of class B: ", __traits(classInstanceSize, B)); } Prints the following: "Size of class A: 8" "Size of class B: 24" An extra 16 bytes for alignment? Is there no options like align(1) to pack the memory of the class A instance inside class B? |
September 07, 2013 Re: std.typecons scoped question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin | Sorry, what I meant was: An extra 8 bytes for alignment |
September 07, 2013 Re: std.typecons scoped question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin | On Saturday, 7 September 2013 at 09:24:29 UTC, Martin wrote:
> Sorry, what I meant was:
> An extra 8 bytes for alignment
AFAIK, the problem is note one of packing, but of aligning the "Payload" regardless of the where the "ScopedResult" itself is located on the stack.
If "A" needs to be 16 aligned, but B is in a position of "4 + 16*N", then the payload will need to shift A an extra 12 bytes.
And I don't think there's any way around this.
THAT SAID, I *think* the current implementation is very conservative. On my machine, B's size is 48 (!).
We could definitely reduce the extra padding.
You should file this as a bug.
|
Copyright © 1999-2021 by the D Language Foundation