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

Meta jared771 at gmail.com
Tue Nov 12 06:48:18 UTC 2019


On Monday, 11 November 2019 at 23:20:31 UTC, Walter Bright wrote:
> On 11/11/2019 12:50 PM, Meta wrote:
>> Would it be enough to put an assert in GC.realloc/extend/free 
>> that asserts the memory is GC-owned, maybe tied to a compiler 
>> switch?
>
> Currently, for `a~=b` if `a` is not owned by the GC, it is 
> copied to a new GC location by the runtime.

Yes, my point being, if the concern is over manually-allocated 
pointers being invalidated by accidental reallocation by the GC, 
wouldn't the absolute least intrusive change possible be to put 
asserts in the relevant GC methods to make sure it's only 
reallocating/extending/freeing memory *it* owns? It would mean a 
crash at runtime only, and only in debug mode, but you get a 
semi-nice stack trace showing you the exact point you're trying 
to do something bad (assuming I properly understand the GC 
implementation, which I may not).


More information about the Digitalmars-d mailing list