Fast GC allocation of many small objects

Per Nordlöw per.nordlow at gmail.com
Sun Apr 1 16:52:10 UTC 2018


On Sunday, 1 April 2018 at 10:59:55 UTC, Alexandru jercaianu 
wrote:
> On Saturday, 31 March 2018 at 20:17:26 UTC, Per Nordlöw wrote:
>> On Friday, 30 March 2018 at 23:09:33 UTC, Alexandru Jercaianu 
>> wrote:
>>> Hello,
>>>
>>> You can try the following:
>>>     struct Node
>>>     {
>>>         char[64] arr;
>>>     }
>>>
>>>      enum numNodes = 100_000_000;
>>>      void[] buf = GCAllocator.instance.allocate(numNodes * 
>>> Node.sizeof);
>>>      auto reg = Region!(NullAllocator, 16)(cast(ubyte[])buf);
>>
>> Thanks!
>>
>> Is a `minAlign` of 16 recommended over 8 when allocating 
>> classes or arrays?
> Hi,
> I'm glad it was helpful.
> To be honest, I don't know which alignment would be better and 
> it probably depends on your machine.
> This here says that 16 would work just fine [1] so I would go 
> with that.
>
> [1] - 
> https://dlang.org/library/std/experimental/allocator/common/platform_alignment.html

Thanks. I presume if we know what type we should allocate, in my 
case a class `C`, we should use `C.alignof` otherwise we should 
default to `platformAlignment`.


More information about the Digitalmars-d-learn mailing list