Memory allocation in D (noob question)
Robert Fraser
fraserofthenight at gmail.com
Fri Nov 30 23:06:13 PST 2007
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.
More information about the Digitalmars-d
mailing list