Re: New adapter: std.allocator.quantizer

2015-05-15 Thread Andrei Alexandrescu via Digitalmars-d
On 5/15/15 1:28 PM, Timon Gehr wrote: I have just noticed that all the calls to alignedAllocate do not pass the alignment argument. Crikey, that must have something to do with all that missing test coverage :o). -- Andrei

Re: New adapter: std.allocator.quantizer

2015-05-15 Thread Andrei Alexandrescu via Digitalmars-d
On 5/12/15 12:57 PM, Timon Gehr wrote: On 05/12/2015 04:54 AM, Andrei Alexandrescu wrote: On 5/11/15 4:59 PM, Timon Gehr wrote: On 05/11/2015 08:48 PM, Andrei Alexandrescu wrote: On 5/11/15 11:31 AM, Timon Gehr wrote: - The assertion in line 141 may fail. (expand can return false.) OK, it

Re: New adapter: std.allocator.quantizer

2015-05-15 Thread Timon Gehr via Digitalmars-d
On 05/15/2015 06:58 PM, Andrei Alexandrescu wrote: On 5/12/15 12:57 PM, Timon Gehr wrote: ... Missed alignedReallocate. :o) On a related note, alignedReallocate is now also buggy in that it does not necessarily align the allocated memory if b.ptr is null. Missed this, thanks for the email!

Re: New adapter: std.allocator.quantizer

2015-05-12 Thread Timon Gehr via Digitalmars-d
On 05/12/2015 04:54 AM, Andrei Alexandrescu wrote: On 5/11/15 4:59 PM, Timon Gehr wrote: On 05/11/2015 08:48 PM, Andrei Alexandrescu wrote: On 5/11/15 11:31 AM, Timon Gehr wrote: - The assertion in line 141 may fail. (expand can return false.) OK, it seems the previous commit should take

Re: New adapter: std.allocator.quantizer

2015-05-11 Thread Andrei Alexandrescu via Digitalmars-d
On 5/10/15 5:08 AM, Timon Gehr wrote: On 05/10/2015 01:48 PM, Timon Gehr wrote: bool expand(ref void[] b, size_t delta); Post: !result || b.length == old(b).length + delta Expands b by delta bytes. If delta == 0, succeeds without changing b. If b is null, the call evaluates b =

Re: New adapter: std.allocator.quantizer

2015-05-11 Thread Timon Gehr via Digitalmars-d
On 05/11/2015 05:28 PM, Andrei Alexandrescu wrote: On 5/10/15 5:08 AM, Timon Gehr wrote: On 05/10/2015 01:48 PM, Timon Gehr wrote: bool expand(ref void[] b, size_t delta); Post: !result || b.length == old(b).length + delta Expands b by delta bytes. If delta == 0, succeeds without

Re: New adapter: std.allocator.quantizer

2015-05-11 Thread Andrei Alexandrescu via Digitalmars-d
On 5/11/15 11:06 AM, Timon Gehr wrote: - If the rounding function is not piecewise constant with one fixed point per piece, it can happen that 'allocated = needed' but 'allocated goodAllocSize(needed)'. Then, the allocated size will be inconsistent with goodAllocSize. (This is why I recommended

Re: New adapter: std.allocator.quantizer

2015-05-11 Thread Timon Gehr via Digitalmars-d
On 05/11/2015 08:06 PM, Timon Gehr wrote: On 05/11/2015 05:28 PM, Andrei Alexandrescu wrote: On 5/10/15 5:08 AM, Timon Gehr wrote: On 05/10/2015 01:48 PM, Timon Gehr wrote: bool expand(ref void[] b, size_t delta); Post: !result || b.length == old(b).length + delta Expands b by delta

Re: New adapter: std.allocator.quantizer

2015-05-11 Thread Timon Gehr via Digitalmars-d
On 05/11/2015 08:31 PM, Timon Gehr wrote: - The assertion in line 141 may fail. (expand can return false.) (Same thing further down, line 167.)

Re: New adapter: std.allocator.quantizer

2015-05-11 Thread Andrei Alexandrescu via Digitalmars-d
On 5/11/15 11:31 AM, Timon Gehr wrote: - The assertion in line 141 may fail. (expand can return false.) OK, it seems the previous commit should take care of that. (Rant: Go on, conflate assert and assume in -release and then, when a sufficiently smart optimizer runs, suddenly expand will

Re: New adapter: std.allocator.quantizer

2015-05-11 Thread Timon Gehr via Digitalmars-d
On 05/11/2015 08:45 PM, Andrei Alexandrescu wrote: On 5/11/15 11:06 AM, Timon Gehr wrote: - If the rounding function is not piecewise constant with one fixed point per piece, it can happen that 'allocated = needed' but 'allocated goodAllocSize(needed)'. Then, the allocated size will be

Re: New adapter: std.allocator.quantizer

2015-05-11 Thread Timon Gehr via Digitalmars-d
On 05/11/2015 08:48 PM, Andrei Alexandrescu wrote: On 5/11/15 11:31 AM, Timon Gehr wrote: - The assertion in line 141 may fail. (expand can return false.) OK, it seems the previous commit should take care of that. ... Nope. Well, yes, in the sense that there is no longer a possibly failing

Re: New adapter: std.allocator.quantizer

2015-05-11 Thread Timon Gehr via Digitalmars-d
On 05/12/2015 01:38 AM, Timon Gehr wrote: - If b.ptr is null, then line 113 is bad in case goodAllocSize(0) 0. That should be fixed in the same commit; I just handle expansion of null blocks up front in expand(). ... OK. (Scrap that.)

Re: New adapter: std.allocator.quantizer

2015-05-11 Thread Andrei Alexandrescu via Digitalmars-d
On 5/11/15 4:59 PM, Timon Gehr wrote: On 05/11/2015 08:48 PM, Andrei Alexandrescu wrote: On 5/11/15 11:31 AM, Timon Gehr wrote: - The assertion in line 141 may fail. (expand can return false.) OK, it seems the previous commit should take care of that. ... Nope. Well, yes, in the sense

Re: New adapter: std.allocator.quantizer

2015-05-10 Thread Timon Gehr via Digitalmars-d
On 05/10/2015 05:29 AM, Andrei Alexandrescu wrote: On 5/9/15 3:38 PM, Timon Gehr wrote: Thanks! Looks good, except: 106| if (!parent.expand(b, goodAllocSize(needed) - b.length)) Let's see, this is a tad tricky. needed is the needed size, i.e. b.length + delta. We want to expand to a final

Re: New adapter: std.allocator.quantizer

2015-05-10 Thread Timon Gehr via Digitalmars-d
On 05/10/2015 05:32 AM, Andrei Alexandrescu wrote: On 5/9/15 3:41 PM, Timon Gehr wrote: On 05/10/2015 12:38 AM, Timon Gehr wrote: 142| return parent.reallocate(b, gs); 172| return parent.alignedReallocate(b, gs, a); (Note that those code snippets also occur in their documentation.) Can't

Re: New adapter: std.allocator.quantizer

2015-05-10 Thread Timon Gehr via Digitalmars-d
On 05/10/2015 05:38 AM, Andrei Alexandrescu wrote: 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

Re: New adapter: std.allocator.quantizer

2015-05-10 Thread Timon Gehr via Digitalmars-d
On 05/10/2015 01:48 PM, Timon Gehr wrote: bool expand(ref void[] b, size_t delta); Post: !result || b.length == old(b).length + delta Expands b by delta bytes. If delta == 0, succeeds without changing b. If b is null, the call evaluates b = allocate(delta) and returns b !is null.

Re: New adapter: std.allocator.quantizer

2015-05-10 Thread Andrei Alexandrescu via Digitalmars-d
On 5/10/15 12:52 AM, Marco Leise wrote: * zeroesAllocations I called it elementsAreInited and as the name suggests, it tells whether new elements receive their T.init automatically. Now std.allocator deals mostly with raw memory, so zeroing is the only option, but I can see some

Re: New adapter: std.allocator.quantizer

2015-05-10 Thread Marco Leise via Digitalmars-d
Am Thu, 07 May 2015 14:12:40 -0700 schrieb Andrei Alexandrescu seewebsiteforem...@erdani.org: Helps an allocator without good reallocation capabilities: http://erdani.com/d/phobos-prerelease/std_experimental_allocator_quantizer.html Destruction welcome. Andrei I haven't tested it,

Re: New adapter: std.allocator.quantizer

2015-05-10 Thread Andrei Alexandrescu via Digitalmars-d
On 5/10/15 4:48 AM, Timon Gehr wrote: Yes, but 'expand' expects a _full_ block that was allocated by that allocator: Ah, now I understand. Thanks, will fix! -- Andrei

Re: New adapter: std.allocator.quantizer

2015-05-10 Thread Andrei Alexandrescu via Digitalmars-d
On 5/10/15 5:02 AM, Timon Gehr wrote: size_t brokenRoundingFunction(size_t siz){ if(siz==10) return 40; if(siz==20) return 30; return siz; } Say no more, got it. I'll change the docs. -- Andrei

Re: New adapter: std.allocator.quantizer

2015-05-10 Thread Andrei Alexandrescu via Digitalmars-d
On 5/10/15 5:08 AM, Timon Gehr wrote: On 05/10/2015 01:48 PM, Timon Gehr wrote: bool expand(ref void[] b, size_t delta); Post: !result || b.length == old(b).length + delta Expands b by delta bytes. If delta == 0, succeeds without changing b. If b is null, the call evaluates b =

Re: New adapter: std.allocator.quantizer

2015-05-09 Thread Timon Gehr via Digitalmars-d
On 05/10/2015 12:38 AM, Timon Gehr wrote: 142| return parent.reallocate(b, gs); 172| return parent.alignedReallocate(b, gs, a); (Note that those code snippets also occur in their documentation.)

Re: New adapter: std.allocator.quantizer

2015-05-09 Thread Andrei Alexandrescu via Digitalmars-d
On 5/9/15 3:41 PM, Timon Gehr wrote: On 05/10/2015 12:38 AM, Timon Gehr wrote: 142| return parent.reallocate(b, gs); 172| return parent.alignedReallocate(b, gs, a); (Note that those code snippets also occur in their documentation.) Can't find gs in the doc comments, is it there? -- Andrei

Re: New adapter: std.allocator.quantizer

2015-05-09 Thread Timon Gehr via Digitalmars-d
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

Re: New adapter: std.allocator.quantizer

2015-05-09 Thread Andrei Alexandrescu via Digitalmars-d
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

Re: New adapter: std.allocator.quantizer

2015-05-09 Thread Timon Gehr via Digitalmars-d
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.)

Re: New adapter: std.allocator.quantizer

2015-05-09 Thread Andrei Alexandrescu via Digitalmars-d
On 5/9/15 3:38 PM, Timon Gehr wrote: Thanks! Looks good, except: 106| if (!parent.expand(b, goodAllocSize(needed) - b.length)) Let's see, this is a tad tricky. needed is the needed size, i.e. b.length + delta. We want to expand to a final size of goodAllocSize(needed). So we need to pass

Re: New adapter: std.allocator.quantizer

2015-05-09 Thread Andrei Alexandrescu via Digitalmars-d
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

Re: New adapter: std.allocator.quantizer

2015-05-09 Thread Timon Gehr via Digitalmars-d
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:

New adapter: std.allocator.quantizer

2015-05-07 Thread Andrei Alexandrescu via Digitalmars-d
Helps an allocator without good reallocation capabilities: http://erdani.com/d/phobos-prerelease/std_experimental_allocator_quantizer.html Destruction welcome. Andrei