resizeable arrays: T[new]

Walter Bright newshound1 at digitalmars.com
Wed Jun 6 22:33:33 PDT 2007


Sean Kelly wrote:
> Given the above, am I correct in assuming that it will only be illegal 
> to resize an array via .length if the underlying data is const?  If the 
> data is not const then it seems completely legitimate to resize the 
> supplied array, even if doing so means an in-place expansion.

Making the referred to data const does not inhibit resizing, because 
resizing does not change the referred to data.

The key to understanding dynamic arrays is understanding their 
representation. Dynamic arrays of const data are like a C++ struct 
defined as:

struct DynamicArray
{
	size_t length;
	const char *ptr;
}

Here, I can change .length and .ptr EVEN THOUGH the data being pointed 
to is const.



More information about the Digitalmars-d-announce mailing list