On Friday, 19 February 2021 at 08:04:19 UTC, Виталий Фадеев wrote:
We have:
class File
{
// WIN32_FIND_DATAW data;
}
void fastReadDir()
{
File[] files;
// reserve space, allocating instances
files = new File[]( 1000 ); // <--- trouble here ?
// filling instances
auto file = files.ptr;
writeln( file.data ); // <--- or trouble here ?
// ...
}
Got:
SegFault
Goal:
Allocate memory for 1000 instances at once.
Source:
https://run.dlang.io/is/xfaXcv
Question:
What is the true, fastest, beauty way to create 1000
instances of the class File ?
files = new File[]( 1000 );
files[] = new File(); // add this
Since classes are reference types all instances of files will be
the same reference of "new File()", which you probably don't want.