New adapter: std.allocator.quantizer

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sat May 9 15:38:46 PDT 2015


On 05/09/2015 06:09 PM, Andrei Alexandrescu wrote:
> On 5/9/15 6:27 AM, Timon Gehr wrote:
>> On 05/07/2015 11:12 PM, Andrei Alexandrescu wrote:
>>> Helps an allocator without good reallocation capabilities:
>>>
>>> http://erdani.com/d/phobos-prerelease/std_experimental_allocator_quantizer.html
>>>
>>>
>>>
>>>
>>> Destruction welcome.
>>>
>>>
>>> Andrei
>>
>> quantizer.d is not in the commit:
>> https://github.com/andralex/phobos/commit/1b75d3e9dfc37f1d074e217dee2931463dec5191
>>
>
> How embarrassing. Thanks for letting me know.
>
> https://github.com/D-Programming-Language/phobos/commit/c23913b9082a4dda9156314645e011eaa0a3af8c
>
>
> Andrei
>

Thanks! Looks good, except:

106| if (!parent.expand(b, goodAllocSize(needed) - b.length))

142| return parent.reallocate(b, gs);

172| return parent.alignedReallocate(b, gs, a);

Those should be more like:

182| parent.deallocate(b.ptr[0 .. goodAllocSize(b.length)]);


Another point is that the documented/checked constraints on the rounding 
function are too weak. A rounding function should be monotone increasing 
and piecewise constant with one fixed point per piece.

In case the given function does not have those properties, a call to 
'expand' can destroy the invariant that the memory block of b is always 
of size goodAllocSize(b.length).




And then, there's this, of course:

size_t goodAllocSize(size_t n);
     Returns roundingFunction(n). It is required that 
roundingFunction(n) >= n. For efficiency reasons, this is only asserted 
(checked in debug mode).

Is this meant to be a complete specification of 'assert'? :o)
What is 'debug mode'?




More information about the Digitalmars-d mailing list