I use D to solve the programming problems  on projecteuler ( 
http://projecteuler.net/ )


I thought D should be as fast as C++, but it turns out that sometimes D is much 
slower.

It seems that array would reallocate its memory every time the  ~= operation is 
invoked.
If I push 10^7 numbers into an array, the realloc would be called for 10^7 
times.
That would be at least 100 times slower than C++STL.


So I don't use ~= and manage the length of the array myself 
When the length is not enough, I reallocate the memory with the size of  
requiredSize * 9 / 8. ( In STL, it's oldSize *  2. )
9/8 could save a lot of memory, and the attached source code shows that *9/8 is 
almost as fast as *2 .

My question is:
Is there any other way to solve this problem?
I think this kind of optimization should be implemented in the compiler or the 
D runtime.

Attachment: ArrayMemory.d
Description: Binary data

Reply via email to