@safe containers with std.experimental.allocator

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 20 21:52:49 PST 2017


On Saturday, 21 January 2017 at 05:06:07 UTC, Eugene Wissner 
wrote:
> Alligned allocator isn't present in the 
> std.experimental.allocator because IAllocator has a method 
> alignedAllocate()

I hadn't noticed this, but I immediately see two problems:

1) there is no alignedDeallocate() which is needed because 
aligned allocators usually prepend metadata containing a pointer 
to the actual start of the memory to be passed to free(). So 
deallocate() can't know if the memory came from allocate() or 
alignedAllocate(), and hence does not now how to properly free 
the memory.

2) The whole point of using an allocator is that is allocates 
memory in a different way, but provides a standard interface. It 
shouldn't be up to a container to know whether to call allocate() 
or alignedAllocate(). A container should simply call allocate() 
of whatever allocator it was given.



More information about the Digitalmars-d mailing list