Re: How to reserve memory for a slice in a struct

2013-05-08 Thread John Colvin
On Tuesday, 7 May 2013 at 11:49:07 UTC, evilrat wrote: On Tuesday, 7 May 2013 at 10:58:42 UTC, John Colvin wrote: ... int a[]; please don't use C style declarations, D style is "type followed by id": int[] a; woops, just copied it from the original post.

Re: How to reserve memory for a slice in a struct

2013-05-07 Thread Diggory
You could allocate space inside a class itself with something like this: class Base { int[] slice; } template Derived(size_t N) { class Derived : Base { int[N] array; this() { slice = array; } } } Base b = new Derived!32(); A bit pointless thoug

Re: How to reserve memory for a slice in a struct

2013-05-07 Thread Maxim Fomin
On Tuesday, 7 May 2013 at 10:29:44 UTC, Namal wrote: Hello, I am new to D. According to that power of 2 rule I want to reserve 2 sized chunks to my array, But how do I do that in a struct? You can set some kind of statically allocated array size: struct S { int[] a; this(size_

Re: How to reserve memory for a slice in a struct

2013-05-07 Thread Steven Schveighoffer
On Tue, 07 May 2013 06:29:43 -0400, Namal wrote: Hello, I am new to D. According to that power of 2 rule I want to reserve 2 sized chunks to my array, But how do I do that in a struct? Say: struct Stack(int){ int a[]; } Where do I put that a.reserve(2); Because right after the declarati

Re: How to reserve memory for a slice in a struct

2013-05-07 Thread evilrat
On Tuesday, 7 May 2013 at 10:58:42 UTC, John Colvin wrote: ... int a[]; please don't use C style declarations, D style is "type followed by id": int[] a;

Re: How to reserve memory for a slice in a struct

2013-05-07 Thread John Colvin
On Tuesday, 7 May 2013 at 10:29:44 UTC, Namal wrote: Hello, I am new to D. According to that power of 2 rule I want to reserve 2 sized chunks to my array, But how do I do that in a struct? Say: struct Stack(int){ int a[]; } "2 sized chunks"? Perhaps you want something like this: struct