Setting array length without initializing/reallocating.

Dukc ajieskola at gmail.com
Sun Dec 13 13:26:29 UTC 2020


On Sunday, 13 December 2020 at 13:19:35 UTC, Dukc wrote:
> ```
> @safe resizedWithin(T)(T[] arr, T[] within, size_t newSize)
> {  if(newSize == 0) return arr[0..0];
>    auto startIndex= &arr[0] - &within[0];
>    return within[startIndex .. startIndex + newSize];
> }
> ```

Okay, there is a bug in my code that it won't work if `arr` is 
originally of length 0. May well contain other bugs, use with 
care :D. But hey, at least no memory corruption, as it's `@safe`.



More information about the Digitalmars-d mailing list