On 3/30/18 4:31 PM, Per Nordlöw wrote:
I'm working on a graph database with tens of millions of small nodes containing typically around 8-64 bytes of member data. Is there a faster way of allocating many small class objects such as

class Node
{
     // abstract members
}

class StrNode : Node
{
     string value;
}

// more Node-types...

other than

const nodeCount = 10_000_000;
foreach (0 .. n)
{
     auto node = new Node(someData);
     // connect node...
}


You may be interested in this proposal, which was inspired by trying to implement a reserve feature for AAs (requires a similar mechanism).

https://issues.dlang.org/show_bug.cgi?id=17881

Note that the recommendations in the replies here have the unfortunate drawback of tying all allocations to one block, scanned by the GC all at once, and will only get collected when none of them are referenced. On 32-bit systems this also leads to a high likelihood of false pointers keeping the block alive.

More use cases for the feature request may help push for acceptance.

-Steve

Reply via email to