How to reserve memory for a slice in a struct

John Colvin john.loughran.colvin at gmail.com
Tue May 7 03:58:41 PDT 2013


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 Stack{
	int a[];
	this(size_t r) {
		a.reserve(r);
	}
}

void main() {
	auto s = Stack(2);
}


More information about the Digitalmars-d-learn mailing list