New adapter: std.allocator.quantizer
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Sat May 9 20:38:01 PDT 2015
On 5/9/15 3:54 PM, Timon Gehr wrote:
> On 05/10/2015 12:38 AM, Timon Gehr wrote:
>> monotone increasing and piecewise constant with one fixed point per
>> piece.
>
> (Note that monotone increasing is implied by piecewise constant with one
> fixed point per piece, so it does not necessarily need to be documented
> separately.)
I think the only requirements are (a) roundingFunction is pure, (b)
roundingFunction(n) >= n. E.g. the identity function works, although
it's not terribly useful.
These could be enforced by Quantizer, but it doesn't feel right. A
designer who is at the same time sophisticated enough to need Quantizer
yet naïve enough to choose a lousy one is quite unlikely. On the other
hand, I can imagine stuff like this could be useful to some:
__gshared uint SMALL_ALLOC = 64;
... configure it via an application-level flag...
alias MyAlloc = Quantizer!(
FreeTree!GCAllocator,
n => n.roundUpToMultipleOf(n <= SMALL_ALLOC ? 64 : 4096));
That's technically not pure but works, and might be appreciated.
Andrei
More information about the Digitalmars-d
mailing list