Setting array length without initializing/reallocating.

Max Haughton maxhaton at gmail.com
Mon Dec 14 20:58:16 UTC 2020


On Monday, 14 December 2020 at 20:53:39 UTC, Jackson22 wrote:
> On Monday, 14 December 2020 at 01:36:02 UTC, Mike Parker wrote:
>> On Sunday, 13 December 2020 at 20:03:46 UTC, Jackson22 wrote:
>>>
>>> There's a reason .ptr exist, I wish people would stop 
>>> pretending that using it where it is appropriate is somehow 
>>> going to lead to failure when there are more successful 
>>> programming languages that have zero automatic bounds 
>>> checking.
>>>
>>
>> There's no pretending here. What the OP is doing *is* 
>> dangerous.
>
> If someone writes a wrapper around .ptr which checks. It'd be 
> literally no different than the implementation in druntime.
>
> Like I said, I wish people would stop pretending that using it 
> where it is appropriate is somehow going to lead to failure. 
> Maybe those people just aren't knowledgeable enough to 
> understand, I don't know.

Good practice is good practice. If you know what you're doing you 
probably shouldn't need to ask.

What Mike is saying is important to know, because even if you use 
exactly the same concept as what druntime does in your code, 
you're still repeating a pattern which will lead to bugs if you 
get it wrong. Good code is all about compartmentalizing bad code, 
especially with memory where (thankfully we have sanitizers now) 
things can often go badly wrong without actually exhibiting any 
side-effects (i.e. we all know why C code has so many security 
problems)


More information about the Digitalmars-d mailing list