DIP 1025--Dynamic Arrays Only Shrink, Never Grow--Community Review Round 1

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Tue Nov 12 17:45:51 UTC 2019

On Tuesday, 12 November 2019 at 17:25:06 UTC, Jab wrote:
> This would be a memory leak, not memory corruption:
>   int[] slice = cast(int*)malloc(10 * int.sizeof)[0 .. 10];
>   slice ~= 1;
>   free(slice.ptr); // Oops!

Depends on the implementation of the garbage collector and C free.

If it frees the beginning of block that the GC has allocated 
using malloc then it would indeed cause memory corruption as soon 
at somebody else get the same block from malloc.

More information about the Digitalmars-d mailing list