Skip to content

Commit

Permalink
Added Quantizer, implemented fixes pointed by reviews by Brian Schott…
Browse files Browse the repository at this point in the history
… and Timon Gehr
  • Loading branch information
andralex committed May 7, 2015
1 parent 28c27fa commit 1b75d3e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ STD_MODULES = $(addprefix std/, \
$(addprefix experimental/allocator/, affix_allocator allocator_list common \
bucketizer fallback_allocator free_list free_tree gc_allocator \
heap_block kernighan_ritchie mallocator mmap_allocator null_allocator \
porcelain region segregator stats_collector) \
porcelain quantizer region segregator stats_collector) \
array ascii base64 bigint bitmanip compiler complex concurrency \
$(addprefix container/, array binaryheap dlist rbtree slist util) \
conv cstream csv datetime demangle \
Expand Down
17 changes: 5 additions & 12 deletions std/experimental/allocator/free_tree.d
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ struct FreeTree(ParentAllocator)
The destructor of $(D FreeTree) releases all memory back to the parent
allocator.
*/
static if (hasMember!(ParentAllocator, "deallocate"))
~this()
{
clear;
Expand Down Expand Up @@ -385,18 +386,10 @@ struct FreeTree(ParentAllocator)
static if (hasMember!(ParentAllocator, "deallocateAll"))
void deallocateAll()
{
static if (hasMember!(ParentAllocator, "deallocateAll"))
{
// This is easy, just nuke the root and deallocate all from the
// parent
root = null;
parent.deallocateAll;
}
else // hasMember!(ParentAllocator, "deallocate")
{
// Must deallocate everything by hand
clear;
}
// This is easy, just nuke the root and deallocate all from the
// parent
root = null;
parent.deallocateAll;
}
}

Expand Down
26 changes: 13 additions & 13 deletions std/experimental/allocator/porcelain.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ and also array primitives related to allocation.
int* p = theAllocator.make!int(42);
assert(*p == 42);
// Destroy and deallocate it
theAllocator.kill(p);
theAllocator.dispose(p);
// Allocate using the global process allocator
p = processAllocator.make!int(100);
assert(*p == 100);
// Destroy and deallocate
processAllocator.kill(p);
processAllocator.dispose(p);
// Create an array of 50 doubles initialized to -1.0
double[] arr = theAllocator.makeArray!double(50, -1.0);
Expand All @@ -24,7 +24,7 @@ theAllocator.growArray(arr, 2, 0.0);
// On second thought, take that back
theAllocator.shrinkArray(arr, 2);
// Destroy and deallocate
theAllocator.kill(arr);
theAllocator.dispose(arr);
---
*/
Expand All @@ -38,13 +38,13 @@ unittest
int* p = theAllocator.make!int(42);
assert(*p == 42);
// Destroy and deallocate it
theAllocator.kill(p);
theAllocator.dispose(p);

// Allocate using the global process allocator
p = processAllocator.make!int(100);
assert(*p == 100);
// Destroy and deallocate
processAllocator.kill(p);
processAllocator.dispose(p);

// Create an array of 50 doubles initialized to -1.0
double[] arr = theAllocator.makeArray!double(50, -1.0);
Expand All @@ -53,7 +53,7 @@ unittest
// On second thought, take that back
theAllocator.shrinkArray(arr, 2);
// Destroy and deallocate
theAllocator.kill(arr);
theAllocator.dispose(arr);
}

import std.experimental.allocator.common;
Expand Down Expand Up @@ -943,7 +943,7 @@ reference, or an entire array. It is assumed the respective entities had been
allocated with the same allocator.
*/
void kill(A, T)(auto ref A alloc, T* p)
void dispose(A, T)(auto ref A alloc, T* p)
{
static if (hasElaborateDestructor!T)
{
Expand All @@ -953,7 +953,7 @@ void kill(A, T)(auto ref A alloc, T* p)
}

/// Ditto
void kill(A, T)(auto ref A alloc, T p)
void dispose(A, T)(auto ref A alloc, T p)
if (is(T == class) || is(T == interface))
{
if (!p) return;
Expand All @@ -963,7 +963,7 @@ if (is(T == class) || is(T == interface))
}

/// Ditto
void kill(A, T)(auto ref A alloc, T[] array)
void dispose(A, T)(auto ref A alloc, T[] array)
{
static if (hasElaborateDestructor!(typeof(array[0])))
{
Expand Down Expand Up @@ -994,23 +994,23 @@ unittest
auto a = theAllocator.make!A;
a.method();
assert(x == 21);
theAllocator.kill(a);
theAllocator.dispose(a);
assert(x == 42);

B b = theAllocator.make!B;
b.method();
assert(x == 21);
theAllocator.kill(b);
theAllocator.dispose(b);
assert(x == 42);

I i = theAllocator.make!B;
i.method();
assert(x == 21);
theAllocator.kill(i);
theAllocator.dispose(i);
assert(x == 42);

int[] arr = theAllocator.makeArray!int(43);
theAllocator.kill(arr);
theAllocator.dispose(arr);
}

/**
Expand Down

0 comments on commit 1b75d3e

Please sign in to comment.