Memory allocation in D (noob question)
mandel
oh at no.es
Sat Dec 1 00:29:46 PST 2007
Robert Fraser Wrote:
> mandel wrote:
> > It probably is a noob question,
> > but aren't array lengths just hidden size_t values
> > that are passed around?
> > Why do we need to allocate space for them, too?
> >
> > voif foo()
> > {
> > size_t length;
> > char* ptr; //allocated memory of 2^n
> > //.. the same as..?
> > char[] data;
> > }
>
> The extra space allocated isn't for the length (in fact, it's just a
> byte I think); it's to make checking for array bounds errors possible
> (since there's a byte of space that, if accessed, indicates an
> overflow). I tmight be used for something else, too.
Thanks, that answers my question.
But I can't think how it could be used for array bounds errors checking right now.
Well, I guess there some ng post about this, somewhere.
But the page allocation overhead looks ugly for a language like D.
Anyway, good to have D arrays. Working with pointers in C was often
ready for surprises in case of reduced attention. :>
More information about the Digitalmars-d
mailing list