std.allocator ready for some abuse

Johannes Pfau nospam at example.com
Sat Oct 26 05:23:50 PDT 2013


Am Thu, 24 Oct 2013 12:54:41 -0700
schrieb Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:

> 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

The overall design looks great!


Some small nitpicks:
* byAllocation is not accessible from outside std.allocator
* Is it intentional that AllocatorWithStats can't log the
  __FUNCTION__ / __PRETTY_FUNCTION__ ?
* The documentation for byAllocation should probably state that it only
  lists 'alive' allocations and that this is especially useful for
  finding memory leaks.


And one bigger problem: CAllocatorImpl doesn't work well with
AllocatorWithStats.

AllocatorWithStats special members (byAllocation, etc) are not
directly accessible. Although we can access them by using .impl it'd be
nice to have a special AllocatorWithStats class which directly exposes
those members.

The second problem is that the logged file/line is always in
std.allocator.d. It's probably not easy to get this working in all
cases (especially regarding polymorphism).


More information about the Digitalmars-d mailing list