delete and __delete not equivalent
Adam D. Ruppe
destructionator at gmail.com
Sat Jan 16 04:52:05 UTC 2021
On Friday, 15 January 2021 at 14:38:55 UTC, Steven Schveighoffer
wrote:
> I'm unsure if deleting from the middle is expected or desired.
Yeah, in my private implementation, I have a sanity check that
the pointer and the base aren't too far apart. I figured they
didn't line up due to a capacity cache or similar metadata at the
beginning of the block (though I didn't prove this) and thus the
pointers shouldn't be more than like 16 bytes apart and anything
more than that is suspicious.
So far in my tests that appears to be exactly the case - 16 bytes
on both 32 and 64 bit.
But while that might be good enough for my barely-documented
"WARNING: calling this function might break your code" thing, idk
if that is the right answer for druntime itself.
However if I can prove it is correct, I do think it is reasonable
to go back to silently doing nothing if the pointers are further
apart since freeing the whole block from a partial slice is a bit
iffy in terms of correctness. You wouldn't do that with malloc.
More information about the Digitalmars-d
mailing list