Possible change to array runtime?

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Sun Mar 16 05:14:15 PDT 2014


On 13/03/14 19:09, Steven Schveighoffer wrote:
> On Thu, 13 Mar 2014 13:44:01 -0400, monarch_dodra <monarchdodra at gmail.com> wrote:
>> The "only way" to make it work (AFAIK), would be for "length = 0" to first
>> finalize the elements in the array. However, you do that, you may accidentally
>> destroy elements that are still "live" and referenced by another array.
>
> In fact, assumeSafeAppend *should* finalize the elements in the array, if it had
> that capability. When you call assumeSafeAppend, you are telling the runtime
> that you are done with the extra elements.
>
>> I'm not too hot about this proposal. My main gripe is that while "length = 0"
>> *may* mean "*I* want to discard this data", there is no guarantee you don't
>> have someone else that has a handle on said data, and sure as hell doesn't
>> want it clobbered.
>
> Again, the =null is a better solution. There is no point to keeping the same
> block in reference, but without any access to elements, unless you want to
> overwrite it.

Problem is, this still seems like safety-by-programmer-virtue.  It's far too 
easy to write ".length = 0" casually and without any attention to consequences 
one way or the other.

Isn't the whole point of the requirement to use assumeSafeAppend that it really 
forces the user to say, "Yes, I want to do away with the contents of the array 
and I take full responsibility for ensuring there's nothing else pointing to it 
that will break" ... ?

I must say that personally I'd rather have the safety-by-default and the 
obligation to write assumeSafeAppend (or use Appender!T) where performance needs 
it, than risk code breaking because someone's function accidentally throws away 
stuff that I still had a slice of.


More information about the Digitalmars-d mailing list