Basic dynamic array question. Use of new versus no new.

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 10 22:46:04 PDT 2014


On 06/10/2014 08:06 PM, Matt wrote:

 > On Wednesday, 11 June 2014 at 02:30:01 UTC, WhatMeWorry wrote:

 >> int[] array; // initially empty
 >> array.length = 5; // now has 5 elements
 >>
 >> while in Mr. Alexandrescu's book, it says
 >>
 >> To create a dynamic array, use a new expression (§ 2.3.6.1 on page 51)
 >> as follows:
 >>
 >> int[] array = new int[20]; // Create an array of 20 integers

 > I would have read the second as creating a static array of 20 ints in
 > heap memory, then assigning a dynamic array to point to it.

Correct but it is not different from the first one, other than doing it 
in one step.

 > Wasn't Andres book based on D1.0? Or has he done another since then?

No. TDPL is a D2 book, which has naturally been behind the newer 
developments since the book has been published. Here is the errata:

   http://erdani.com/tdpl/errata/

Ali



More information about the Digitalmars-d-learn mailing list