std.allocator ready for some abuse

inout inout at gmail.com
Thu Oct 24 21:10:32 PDT 2013


On Thursday, 24 October 2013 at 19:53:56 UTC, Andrei Alexandrescu 
wrote:
> Hello,
>
>
> I know it's been a long wait. Hopefully it was worth it. The 
> alpha release of untyped allocators is ready for tire-kicking 
> and a test drive.
>
> Code: 
> https://github.com/andralex/phobos/blob/allocator/std/allocator.d
>
> Dox: http://erdani.com/d/phobos-prerelease/std_allocator.html
>
> Warning: this is alpha quality. Unit tests are thin, and there 
> are no benchmarks. Both would be appreciated, particularly 
> benchmarks to validate the gains (which I speculate can be very 
> sizable) of custom-built, special-purpose allocators compared 
> to traditional allocators.
>
> I acknowledge I'm clearly in no position to evaluate this 
> design. I have been knocking around it for long enough to have 
> no idea how easy it is to get into it from the outside, or how 
> good it is. By all signs I could gather this feels like good 
> design, and one of the best I've ever put together. The 
> allocators defined have an archetypal feeling, are flexible 
> both statically and dynamically, and morph and combine in 
> infinite ways.
>
> CAllocator and CAllocatorImpl make the link between the static 
> and dynamic worlds. Once an allocator is assembled out of 
> pieces and finely tuned, wrapping it in a dynamic API is a snap.
>
> Please destroy! I've literally sweat as I'm sending this :o).
>
>
> Andrei

Looks good at first glance. A few notes:

- GC.realloc() is nothrow, but you are still catching OOM 
exception in GCAllocator.reallocate(). You don't in other methods 
(e.g. allocate)
- methods aren't marked as nothrow, they probably should be
- I don't understand how UntypedAllocator.collect() works - since 
it is not allowed to store any pointers in it, calling collect() 
on it should just free all allocated memory, right? In this case, 
it might be best to rename it. It will also be beneficial to pass 
proper bitmask attribute to GC.allocate() (e.g. BlkAttr.NO_SCAN).
- Many constants are global lowercase (i.e. platformAlignment, 
unbounded etc). It confused me for a bit when I was reading code 
("where the hell is this variable coming from?").

Will read the rest later.


More information about the Digitalmars-d mailing list