Steven Schveighoffer wrote:
> This should work as you expect.  Can you produce a full code example? 
> Are you reserving space in x before-hand?

Weird; now it works.  I wonder if because I upgraded to 2.043 ... ?  I
understand there was a fix in there for array append.

On the other hand, if the assumeSafeAppend takes place outside the loops
entirely, blow-up occurs -- because the command is not issued after the
array resize to zero?  I've attached examples.

Thanks & best wishes,

    -- Joe
import std.array;
import std.stdio;

void main()
{
	double[] x;

	assumeSafeAppend(x);
	
	foreach(uint i;0..100) {
		x.length = 0;
		
		foreach(uint j;0..5_000) {
			foreach(uint k;0..1_000) {
				x ~= j*k;
			}
		}
		
		writefln("At iteration %u, x has %u elements.",i,x.length);
	}
}
import std.array;
import std.stdio;

void main()
{
	double[] x;

	foreach(uint i;0..100) {
		x.length = 0;
	
		assumeSafeAppend(x);
		
		foreach(uint j;0..5_000) {
			foreach(uint k;0..1_000) {
				x ~= j*k;
			}
		}
		
		writefln("At iteration %u, x has %u elements.",i,x.length);
	}
}

Reply via email to