www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Trying to make FreeList Allocator example compile

reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
I'm trying to compile the example

     import std.experimental.allocator.building_blocks.free_list : 
FreeList;
     theAllocator = allocatorObject(FreeList!8());

at https://dlang.org/phobos/std_experimental_allocator.html but 
fails first because of missing import

     import std.experimental.allocator : allocatorObject, 
theAllocator;

and then, when adding this import, it fails again with the error

/home/per/Work/knet/phobos-next/snippets/gctester.d(127,40): 
Error: template instance `FreeList!8` does not match template 
declaration `FreeList(ParentAllocator, ulong minSize, ulong 
maxSize = minSize, Flag adaptive = No.adaptive)`

Why is this example missing the `ParentAllocator` template 
parameter and what is the preferred type for `ParentAllocator`?
Oct 08 2018
parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Monday, 8 October 2018 at 21:50:33 UTC, Per Nordlöw wrote:
 I'm trying to compile the example

     import std.experimental.allocator.building_blocks.free_list 
 : FreeList;
     theAllocator = allocatorObject(FreeList!8());

 at https://dlang.org/phobos/std_experimental_allocator.html but 
 fails first because of missing import

     import std.experimental.allocator : allocatorObject, 
 theAllocator;

 and then, when adding this import, it fails again with the error

 /home/per/Work/knet/phobos-next/snippets/gctester.d(127,40): 
 Error: template instance `FreeList!8` does not match template 
 declaration `FreeList(ParentAllocator, ulong minSize, ulong 
 maxSize = minSize, Flag adaptive = No.adaptive)`

 Why is this example missing the `ParentAllocator` template 
 parameter and what is the preferred type for `ParentAllocator`?
ParentAllocator can be anything preferred types don't really make sense in a composable design, but it's probably best to go with something like GCAllocator, Mallocator, (Mmap, Sbrk etc.) something that asks the system for more memory for the last fallback so you don't run out of memory.
Oct 08 2018