Setting array length without initializing/reallocating.

rikki cattermole rikki at cattermole.co.nz
Sun Dec 13 17:26:45 UTC 2020


On 14/12/2020 6:01 AM, Jackson22 wrote:
>>>
>>> `array = array.ptr[0..newLength];`
>>
>> You're setting yourself up for failure with that. What are you trying 
>> to "work around"? The allocation, or the initialization?
> 
> How is avoiding an expensive potentially memory leaking operation 
> "setting yourself up for failure"?

No bounds checking. That slice can extend into memory that isn't of that 
type or even allocated to the process.

By avoiding that "expensive" memory operation, you instead create a 
silent memory corruption in its place which is far worse.


More information about the Digitalmars-d mailing list