Is it bad practice to alter dynamic arrays that have references to them?
simendsjo
simen.endsjo at pandavre.com
Thu Aug 5 11:41:12 PDT 2010
On 05.08.2010 19:35, Steven Schveighoffer wrote:
> On Thu, 05 Aug 2010 13:10:44 -0400, simendsjo
> <simen.endsjo at pandavre.com> wrote:
(...)
>
> One helpful function to note is the capacity function:
>
> http://digitalmars.com/d/2.0/phobos/object.html#capacity
>
> This gives you the capacity of the array, or the largest length it can
> be set to without reallocating. If it's 0, that means any append will
> reallocate. This can allow deterministic behavior when appending. Or you
> can just dup the array if you want to ensure you don't mess up the
> original copy.
Ah, that's really good to know! So I can see if it will reallocate using
bool willReallocate = array.capacity < (array.length +
numberOfItemsToAppend)
?
>>
>> Let me know if it's not accepted to crosspost like this.
>
> I think there is no problem with that.
Good, then I'll keep on doing that then.
Thanks a lot for your answer!
> -Steve
More information about the Digitalmars-d-learn
mailing list