How to allocate arrays of objects?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 10 20:34:01 PST 2016


On Thursday, 11 February 2016 at 04:31:12 UTC, cy wrote:
> as[0..$] = new A();
>
> before accessing .stuff on as[0].

Loop through it and allocate each one rather than trying to do it 
in a one liner like that.

> Still no clue why it segfaulted on the allocation though, 
> rather than the statement with the null dereference. Hidden 
> optimization?

The debug info sometimes shows the previous line instead of the 
current line. I betcha if you put some other random thing in 
between like a writeln() it would show that new thing as the line 
number it failed on. I think it is the address of the crash shows 
the last instruction actually finished but I'm not sure.


More information about the Digitalmars-d-learn mailing list