digitalmars.D - std.typecons scoped question
- Martin (23/23) Sep 07 2013 What is the reason behind the wasted memory when using the scoped
- Martin (2/2) Sep 07 2013 Sorry, what I meant was:
- monarch_dodra (11/13) Sep 07 2013 AFAIK, the problem is note one of packing, but of aligning the
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?
Sep 07 2013
Sorry, what I meant was: An extra 8 bytes for alignment
Sep 07 2013
On Saturday, 7 September 2013 at 09:24:29 UTC, Martin wrote:Sorry, what I meant was: An extra 8 bytes for alignmentAFAIK, 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.
Sep 07 2013