built-in array ptrEnd

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Tue Sep 18 13:10:21 PDT 2012


On Tue, 18 Sep 2012 15:43:37 +0200
"monarch_dodra" <monarchdodra at gmail.com> wrote:

> On Tuesday, 18 September 2012 at 12:06:15 UTC, Steven 
> Schveighoffer wrote:
> >
> > There is another reason to avoid this.
> >
> > Note that if I have two consecutive blocks of memory:
> >
> > 0...4
> > and
> > 4...8
> >
> > If we define an array that points to the first block as a 
> > pointer to 0 and a pointer to 4, then that array also 
> > effectively points at the second block (4...8).  The way the GC 
> > works, it will not release the second block as long as you have 
> > a pointer to the first, even though the second pointer is not 
> > technically pointing at the block.
> >
> > -Steve
> 
> That's a good point. I also shows another danger of ptrEnd: Not 
> only is it not a reference to the current range, it could *also* 
> be a reference to an un-related range.

FWIW, a ptrLast would avoid that (ie, arr.ptrLast == &arr[$-1])



More information about the Digitalmars-d mailing list