Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-16 Thread ag0aep6g via Digitalmars-d-learn
On Friday, 16 December 2016 at 18:25:42 UTC, David Zhang wrote: I though all classes were aligned to sizeof(size_t) boundaries? I don't know. Wouldn't it then just be align(sizeof(size_t)) byte[__traits(classInstanceSize, SomeClass)] scStorage; I guess? I really don't have much of a clue

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-16 Thread David Zhang via Digitalmars-d-learn
I haven't considered alignment here. I'm not sure if you have to. I though all classes were aligned to sizeof(size_t) boundaries? Wouldn't it then just be align(sizeof(size_t)) byte[__traits(classInstanceSize, SomeClass)] scStorage;

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread ag0aep6g via Digitalmars-d-learn
On Thursday, 15 December 2016 at 21:37:34 UTC, David Zhang wrote: So the size of Foo would be the size of SomeClass plus members? ie. Is the size of the array stored too? With these definitions: class SomeClass {} class Foo { this() { import std.conv: emplace; em

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread David Zhang via Digitalmars-d-learn
On Thursday, 15 December 2016 at 21:08:51 UTC, ag0aep6g wrote: On 12/15/2016 09:51 PM, David Zhang wrote: However, it leaves me with another question, how much (if any) space would the static array require from the class? Depends on SomeClass. The array's size is just the value of __traits(c

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread ag0aep6g via Digitalmars-d-learn
On 12/15/2016 09:51 PM, David Zhang wrote: However, it leaves me with another question, how much (if any) space would the static array require from the class? Depends on SomeClass. The array's size is just the value of __traits(classInstanceSize, SomeClass). There's no overhead. You can prin

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread David Zhang via Digitalmars-d-learn
Thank you for your responses. Visitor, I don't want any reference to an allocator within the class if I can avoid it. ag0aep6g, thanks! That's what I was looking for. However, it leaves me with another question, how much (if any) space would the static array require from the class? It's not a s

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread ag0aep6g via Digitalmars-d-learn
On 12/15/2016 06:44 PM, David Zhang wrote: It is my understanding that a class can have a struct as one of its members, and it will be allocated in-line with the rest of the class' members. Yup. My question is this; how might I be able to do this with another class? I want to be able to alloc

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread visitor via Digitalmars-d-learn
On Thursday, 15 December 2016 at 17:44:23 UTC, David Zhang wrote: would something like this be a solution ? import std.stdio; import std.experimental.allocator; class SomeClass { int someint = 42; static SomeClass opCall(int a) { auto inst = theAllocator.make!SomeClass;

Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread David Zhang via Digitalmars-d-learn
Hello, It is my understanding that a class can have a struct as one of its members, and it will be allocated in-line with the rest of the class' members. My question is this; how might I be able to do this with another class? I want to be able to allocate Foo using std.experimental.allocator