Hole of new? (Re: Array of array)

Steven Schveighoffer schveiguy at yahoo.com
Sat Jan 7 11:00:28 PST 2012


On Sat, 07 Jan 2012 13:29:25 -0500, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Steven Schveighoffer:
>
>> Interesting trivia, the compiler actually transforms the following:
>>
>> struct S
>> {
>>   int x;
>> }
>>
>> auto s = new S;
>>
>> into this:
>>
>> auto s = (new S[1]).ptr;
>>
>> Found that out when revamping the array allocation code.  It's one thing
>> that still bugs me because this means s will be initialized as an
>> appendable array when it doesn't have to be.
>
> What are the disadvantages caused by this?

Wasted space.  An appendable array requires extra space at the end of the  
block to store the 'used' length.

> If the disadvantages are significant is this improvement in Bugzilla as  
> enhancement request?

It's not in bugzilla, but it's strictly a performance thing, I don't think  
the current method causes any harm, it's just not as optimal as it could  
be.

-Steve


More information about the Digitalmars-d-learn mailing list