On 04/10/2013 10:04 PM, Andrey wrote:> Hello!

>      int arr[];
>      int length = 100_000_000;
>      for (int i=0; i<10; i++)
>      {
>          arr.length = length; // always new memory blocks, why?

The slice does not know what other slices may be sharing the same elements. So, increasing the length of a slice will relocate the elements (almost always, with exceptions.) The following article goes into a lot of detail:

  http://dlang.org/d-array-article.html

>          arr[90] = 20;
>          writeln("After allocation. Press a key.");
>          stdin.readln();
>
>          clear(arr);
>          arr.length = 0; // must be deallocation? but nothing happens

Are you compiling as a 32-bit application? Then, chances are random bit patterns look like references into these slices. (dmd uses a conservative garbage collector). Try compiling with -m64.

Ali

Reply via email to