mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 09:00:22 +03:00
Moved a bunch of building blocks into a new package building_blocks
This commit is contained in:
parent
e0ad05d7b0
commit
499ecfedc5
19 changed files with 116 additions and 94 deletions
13
posix.mak
13
posix.mak
|
@ -151,7 +151,8 @@ P2MODULES=$(foreach P,$1,$(addprefix $P/,$(PACKAGE_$(subst /,_,$P))))
|
||||||
# xy/zz is in variable PACKAGE_xy_zz. This allows automation in iterating
|
# xy/zz is in variable PACKAGE_xy_zz. This allows automation in iterating
|
||||||
# packages and their modules.
|
# packages and their modules.
|
||||||
STD_PACKAGES = std $(addprefix std/,\
|
STD_PACKAGES = std $(addprefix std/,\
|
||||||
algorithm container digest experimental/allocator experimental/logger net \
|
algorithm container digest experimental/allocator \
|
||||||
|
experimental/allocator/building_blocks experimental/logger net \
|
||||||
range regex)
|
range regex)
|
||||||
|
|
||||||
# Modules broken down per package
|
# Modules broken down per package
|
||||||
|
@ -169,10 +170,12 @@ PACKAGE_std_digest = crc digest hmac md ripemd sha
|
||||||
PACKAGE_std_experimental_logger = core filelogger \
|
PACKAGE_std_experimental_logger = core filelogger \
|
||||||
nulllogger multilogger package
|
nulllogger multilogger package
|
||||||
PACKAGE_std_experimental_allocator = \
|
PACKAGE_std_experimental_allocator = \
|
||||||
affix_allocator allocator_list bucketizer building_blocks common \
|
common gc_allocator mallocator mmap_allocator package showcase typed
|
||||||
fallback_allocator free_list free_tree gc_allocator bitmapped_block \
|
PACKAGE_std_experimental_allocator_building_blocks = \
|
||||||
kernighan_ritchie mallocator mmap_allocator null_allocator package quantizer \
|
affix_allocator allocator_list bucketizer \
|
||||||
region scoped_allocator segregator showcase stats_collector typed
|
fallback_allocator free_list free_tree bitmapped_block \
|
||||||
|
kernighan_ritchie null_allocator package quantizer \
|
||||||
|
region scoped_allocator segregator stats_collector
|
||||||
PACKAGE_std_net = curl isemail
|
PACKAGE_std_net = curl isemail
|
||||||
PACKAGE_std_range = interfaces package primitives
|
PACKAGE_std_range = interfaces package primitives
|
||||||
PACKAGE_std_regex = package $(addprefix internal/,generator ir parser \
|
PACKAGE_std_regex = package $(addprefix internal/,generator ir parser \
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module std.experimental.allocator.affix_allocator;
|
module std.experimental.allocator.building_blocks.affix_allocator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
|
@ -268,7 +268,8 @@ unittest
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.bitmapped_block : BitmappedBlock;
|
import std.experimental.allocator.building_blocks.bitmapped_block
|
||||||
|
: BitmappedBlock;
|
||||||
import std.experimental.allocator.common : testAllocator;
|
import std.experimental.allocator.common : testAllocator;
|
||||||
testAllocator!({
|
testAllocator!({
|
||||||
auto a = AffixAllocator!(BitmappedBlock!128, ulong, ulong)
|
auto a = AffixAllocator!(BitmappedBlock!128, ulong, ulong)
|
||||||
|
@ -285,7 +286,8 @@ unittest
|
||||||
A.instance.prefix(b) = 10;
|
A.instance.prefix(b) = 10;
|
||||||
assert(A.instance.prefix(b) == 10);
|
assert(A.instance.prefix(b) == 10);
|
||||||
|
|
||||||
import std.experimental.allocator.null_allocator : NullAllocator;
|
import std.experimental.allocator.building_blocks.null_allocator
|
||||||
|
: NullAllocator;
|
||||||
alias B = AffixAllocator!(NullAllocator, size_t);
|
alias B = AffixAllocator!(NullAllocator, size_t);
|
||||||
b = B.instance.allocate(100);
|
b = B.instance.allocate(100);
|
||||||
assert(b is null);
|
assert(b is null);
|
|
@ -1,7 +1,7 @@
|
||||||
module std.experimental.allocator.allocator_list;
|
module std.experimental.allocator.building_blocks.allocator_list;
|
||||||
|
|
||||||
import std.experimental.allocator.common;
|
import std.experimental.allocator.common;
|
||||||
import std.experimental.allocator.null_allocator;
|
import std.experimental.allocator.building_blocks.null_allocator;
|
||||||
import std.experimental.allocator.gc_allocator;
|
import std.experimental.allocator.gc_allocator;
|
||||||
version(unittest) import std.stdio;
|
version(unittest) import std.stdio;
|
||||||
|
|
||||||
|
@ -65,7 +65,8 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator)
|
||||||
import std.traits : hasMember;
|
import std.traits : hasMember;
|
||||||
import std.conv : emplace;
|
import std.conv : emplace;
|
||||||
import std.algorithm : min, move;
|
import std.algorithm : min, move;
|
||||||
import std.experimental.allocator.stats_collector : StatsCollector, Options;
|
import std.experimental.allocator.building_blocks.stats_collector
|
||||||
|
: StatsCollector, Options;
|
||||||
|
|
||||||
private enum ouroboros = is(BookkeepingAllocator == NullAllocator);
|
private enum ouroboros = is(BookkeepingAllocator == NullAllocator);
|
||||||
|
|
||||||
|
@ -523,10 +524,11 @@ template AllocatorList(alias factoryFunction,
|
||||||
version(Posix) unittest
|
version(Posix) unittest
|
||||||
{
|
{
|
||||||
import std.algorithm : max;
|
import std.algorithm : max;
|
||||||
import std.experimental.allocator.region : Region;
|
import std.experimental.allocator.building_blocks.region : Region;
|
||||||
import std.experimental.allocator.mmap_allocator : MmapAllocator;
|
import std.experimental.allocator.mmap_allocator : MmapAllocator;
|
||||||
import std.experimental.allocator.segregator : Segregator;
|
import std.experimental.allocator.building_blocks.segregator : Segregator;
|
||||||
import std.experimental.allocator.free_list : ContiguousFreeList;
|
import std.experimental.allocator.building_blocks.free_list
|
||||||
|
: ContiguousFreeList;
|
||||||
|
|
||||||
// Ouroboros allocator list based upon 4MB regions, fetched directly from
|
// Ouroboros allocator list based upon 4MB regions, fetched directly from
|
||||||
// mmap. All memory is released upon destruction.
|
// mmap. All memory is released upon destruction.
|
||||||
|
@ -565,7 +567,7 @@ unittest
|
||||||
{
|
{
|
||||||
// Create an allocator based upon 4MB regions, fetched from the GC heap.
|
// Create an allocator based upon 4MB regions, fetched from the GC heap.
|
||||||
import std.algorithm : max;
|
import std.algorithm : max;
|
||||||
import std.experimental.allocator.region : Region;
|
import std.experimental.allocator.building_blocks.region : Region;
|
||||||
AllocatorList!((n) => Region!GCAllocator(new void[max(n, 1024 * 4096)]),
|
AllocatorList!((n) => Region!GCAllocator(new void[max(n, 1024 * 4096)]),
|
||||||
NullAllocator) a;
|
NullAllocator) a;
|
||||||
const b1 = a.allocate(1024 * 8192);
|
const b1 = a.allocate(1024 * 8192);
|
||||||
|
@ -579,7 +581,7 @@ unittest
|
||||||
{
|
{
|
||||||
// Create an allocator based upon 4MB regions, fetched from the GC heap.
|
// Create an allocator based upon 4MB regions, fetched from the GC heap.
|
||||||
import std.algorithm : max;
|
import std.algorithm : max;
|
||||||
import std.experimental.allocator.region : Region;
|
import std.experimental.allocator.building_blocks.region : Region;
|
||||||
AllocatorList!((n) => Region!()(new void[max(n, 1024 * 4096)])) a;
|
AllocatorList!((n) => Region!()(new void[max(n, 1024 * 4096)])) a;
|
||||||
auto b1 = a.allocate(1024 * 8192);
|
auto b1 = a.allocate(1024 * 8192);
|
||||||
assert(b1 !is null); // still works due to overdimensioning
|
assert(b1 !is null); // still works due to overdimensioning
|
||||||
|
@ -591,7 +593,7 @@ unittest
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.algorithm : max;
|
import std.algorithm : max;
|
||||||
import std.experimental.allocator.region : Region;
|
import std.experimental.allocator.building_blocks.region : Region;
|
||||||
AllocatorList!((n) => Region!()(new void[max(n, 1024 * 4096)])) a;
|
AllocatorList!((n) => Region!()(new void[max(n, 1024 * 4096)])) a;
|
||||||
auto b1 = a.allocate(1024 * 8192);
|
auto b1 = a.allocate(1024 * 8192);
|
||||||
assert(b1 !is null);
|
assert(b1 !is null);
|
|
@ -1,7 +1,7 @@
|
||||||
module std.experimental.allocator.bitmapped_block;
|
module std.experimental.allocator.building_blocks.bitmapped_block;
|
||||||
|
|
||||||
import std.experimental.allocator.common;
|
import std.experimental.allocator.common;
|
||||||
import std.experimental.allocator.null_allocator;
|
import std.experimental.allocator.building_blocks.null_allocator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
|
@ -711,7 +711,7 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
// Create a block allocator on top of a 10KB stack region.
|
// Create a block allocator on top of a 10KB stack region.
|
||||||
import std.experimental.allocator.region : InSituRegion;
|
import std.experimental.allocator.building_blocks.region : InSituRegion;
|
||||||
import std.traits : hasMember;
|
import std.traits : hasMember;
|
||||||
InSituRegion!(10_240, 64) r;
|
InSituRegion!(10_240, 64) r;
|
||||||
auto a = BitmappedBlock!(64, 64)(r.allocateAll());
|
auto a = BitmappedBlock!(64, 64)(r.allocateAll());
|
|
@ -1,4 +1,4 @@
|
||||||
module std.experimental.allocator.bucketizer;
|
module std.experimental.allocator.building_blocks.bucketizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step)
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.free_list : FreeList;
|
import std.experimental.allocator.building_blocks.free_list : FreeList;
|
||||||
import std.experimental.allocator.mallocator : Mallocator;
|
import std.experimental.allocator.mallocator : Mallocator;
|
||||||
import std.experimental.allocator.common : unbounded;
|
import std.experimental.allocator.common : unbounded;
|
||||||
Bucketizer!(FreeList!(Mallocator, 0, unbounded),
|
Bucketizer!(FreeList!(Mallocator, 0, unbounded),
|
|
@ -1,4 +1,4 @@
|
||||||
module std.experimental.allocator.fallback_allocator;
|
module std.experimental.allocator.building_blocks.fallback_allocator;
|
||||||
|
|
||||||
import std.experimental.allocator.common;
|
import std.experimental.allocator.common;
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ struct FallbackAllocator(Primary, Fallback)
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.region : InSituRegion;
|
import std.experimental.allocator.building_blocks.region : InSituRegion;
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.conv : text;
|
import std.conv : text;
|
||||||
FallbackAllocator!(InSituRegion!16_384, GCAllocator) a;
|
FallbackAllocator!(InSituRegion!16_384, GCAllocator) a;
|
||||||
|
@ -343,7 +343,7 @@ fallbackAllocator(Primary, Fallback)(auto ref Primary p, auto ref Fallback f)
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.region : Region;
|
import std.experimental.allocator.building_blocks.region : Region;
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
auto a = fallbackAllocator(Region!GCAllocator(1024), GCAllocator.instance);
|
auto a = fallbackAllocator(Region!GCAllocator(1024), GCAllocator.instance);
|
||||||
auto b1 = a.allocate(1020);
|
auto b1 = a.allocate(1020);
|
|
@ -1,4 +1,4 @@
|
||||||
module std.experimental.allocator.free_list;
|
module std.experimental.allocator.building_blocks.free_list;
|
||||||
|
|
||||||
import std.experimental.allocator.common;
|
import std.experimental.allocator.common;
|
||||||
import std.typecons : Flag, Yes, No;
|
import std.typecons : Flag, Yes, No;
|
||||||
|
@ -424,8 +424,10 @@ available for $(D ContiguousFreeList).
|
||||||
struct ContiguousFreeList(ParentAllocator,
|
struct ContiguousFreeList(ParentAllocator,
|
||||||
size_t minSize, size_t maxSize = minSize)
|
size_t minSize, size_t maxSize = minSize)
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.null_allocator : NullAllocator;
|
import std.experimental.allocator.building_blocks.null_allocator
|
||||||
import std.experimental.allocator.stats_collector : StatsCollector, Options;
|
: NullAllocator;
|
||||||
|
import std.experimental.allocator.building_blocks.stats_collector
|
||||||
|
: StatsCollector, Options;
|
||||||
import std.traits : hasMember;
|
import std.traits : hasMember;
|
||||||
|
|
||||||
alias Impl = FreeList!(NullAllocator, minSize, maxSize);
|
alias Impl = FreeList!(NullAllocator, minSize, maxSize);
|
||||||
|
@ -668,7 +670,8 @@ struct ContiguousFreeList(ParentAllocator,
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.experimental.allocator.allocator_list : AllocatorList;
|
import std.experimental.allocator.building_blocks.allocator_list
|
||||||
|
: AllocatorList;
|
||||||
|
|
||||||
alias ScalableFreeList = AllocatorList!((n) =>
|
alias ScalableFreeList = AllocatorList!((n) =>
|
||||||
ContiguousFreeList!(GCAllocator, 0, unbounded)(4096)
|
ContiguousFreeList!(GCAllocator, 0, unbounded)(4096)
|
||||||
|
@ -677,7 +680,8 @@ unittest
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.null_allocator : NullAllocator;
|
import std.experimental.allocator.building_blocks.null_allocator
|
||||||
|
: NullAllocator;
|
||||||
alias A = ContiguousFreeList!(NullAllocator, 0, 64);
|
alias A = ContiguousFreeList!(NullAllocator, 0, 64);
|
||||||
auto a = A(new void[1024]);
|
auto a = A(new void[1024]);
|
||||||
|
|
||||||
|
@ -700,7 +704,7 @@ unittest
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.region : Region;
|
import std.experimental.allocator.building_blocks.region : Region;
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
alias A = ContiguousFreeList!(Region!GCAllocator, 0, 64);
|
alias A = ContiguousFreeList!(Region!GCAllocator, 0, 64);
|
||||||
auto a = A(Region!GCAllocator(1024 * 4), 1024);
|
auto a = A(Region!GCAllocator(1024 * 4), 1024);
|
|
@ -1,4 +1,4 @@
|
||||||
module std.experimental.allocator.free_tree;
|
module std.experimental.allocator.building_blocks.free_tree;
|
||||||
|
|
||||||
import std.experimental.allocator.common;
|
import std.experimental.allocator.common;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module std.experimental.allocator.kernighan_ritchie;
|
module std.experimental.allocator.building_blocks.kernighan_ritchie;
|
||||||
import std.experimental.allocator.null_allocator;
|
import std.experimental.allocator.building_blocks.null_allocator;
|
||||||
|
|
||||||
//debug = KRRegion;
|
//debug = KRRegion;
|
||||||
debug(KRRegion) import std.stdio;
|
debug(KRRegion) import std.stdio;
|
||||||
|
@ -597,7 +597,8 @@ fronting the GC allocator.
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.experimental.allocator.fallback_allocator : fallbackAllocator;
|
import std.experimental.allocator.building_blocks.fallback_allocator
|
||||||
|
: fallbackAllocator;
|
||||||
import std.experimental.allocator.common : Ternary;
|
import std.experimental.allocator.common : Ternary;
|
||||||
// KRRegion fronting a general-purpose allocator
|
// KRRegion fronting a general-purpose allocator
|
||||||
ubyte[1024 * 128] buf;
|
ubyte[1024 * 128] buf;
|
||||||
|
@ -622,7 +623,8 @@ unittest
|
||||||
import std.algorithm : max;
|
import std.algorithm : max;
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.experimental.allocator.mmap_allocator : MmapAllocator;
|
import std.experimental.allocator.mmap_allocator : MmapAllocator;
|
||||||
import std.experimental.allocator.allocator_list : AllocatorList;
|
import std.experimental.allocator.building_blocks.allocator_list
|
||||||
|
: AllocatorList;
|
||||||
AllocatorList!(n => KRRegion!MmapAllocator(max(n * 16, 1024 * 1024))) alloc;
|
AllocatorList!(n => KRRegion!MmapAllocator(max(n * 16, 1024 * 1024))) alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,7 +634,8 @@ unittest
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.experimental.allocator.common : Ternary;
|
import std.experimental.allocator.common : Ternary;
|
||||||
import std.experimental.allocator.mallocator : Mallocator;
|
import std.experimental.allocator.mallocator : Mallocator;
|
||||||
import std.experimental.allocator.allocator_list : AllocatorList;
|
import std.experimental.allocator.building_blocks.allocator_list
|
||||||
|
: AllocatorList;
|
||||||
/*
|
/*
|
||||||
Create a scalable allocator consisting of 1 MB (or larger) blocks fetched
|
Create a scalable allocator consisting of 1 MB (or larger) blocks fetched
|
||||||
from the garbage-collected heap. Each block is organized as a KR-style
|
from the garbage-collected heap. Each block is organized as a KR-style
|
||||||
|
@ -664,7 +667,8 @@ unittest
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.experimental.allocator.common : Ternary;
|
import std.experimental.allocator.common : Ternary;
|
||||||
import std.experimental.allocator.mmap_allocator : MmapAllocator;
|
import std.experimental.allocator.mmap_allocator : MmapAllocator;
|
||||||
import std.experimental.allocator.allocator_list : AllocatorList;
|
import std.experimental.allocator.building_blocks.allocator_list
|
||||||
|
: AllocatorList;
|
||||||
/*
|
/*
|
||||||
Create a scalable allocator consisting of 1 MB (or larger) blocks fetched
|
Create a scalable allocator consisting of 1 MB (or larger) blocks fetched
|
||||||
from the garbage-collected heap. Each block is organized as a KR-style
|
from the garbage-collected heap. Each block is organized as a KR-style
|
||||||
|
@ -698,7 +702,8 @@ unittest
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.experimental.allocator.allocator_list : AllocatorList;
|
import std.experimental.allocator.building_blocks.allocator_list
|
||||||
|
: AllocatorList;
|
||||||
import std.algorithm : max;
|
import std.algorithm : max;
|
||||||
import std.experimental.allocator.common : testAllocator;
|
import std.experimental.allocator.common : testAllocator;
|
||||||
testAllocator!(() => AllocatorList!(
|
testAllocator!(() => AllocatorList!(
|
|
@ -1,4 +1,4 @@
|
||||||
module std.experimental.allocator.null_allocator;
|
module std.experimental.allocator.building_blocks.null_allocator;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
_ _ _ _ _ _ _
|
_ _ _ _ _ _ _
|
|
@ -202,7 +202,7 @@ or `import` `std.experimental.building_blocks`, which imports them all
|
||||||
combined with your own. For a collection of typical and useful preassembled
|
combined with your own. For a collection of typical and useful preassembled
|
||||||
allocators and for inspiration in defining more such assemblies, refer to
|
allocators and for inspiration in defining more such assemblies, refer to
|
||||||
$(LINK2 std_experimental_allocator_showcase.html,
|
$(LINK2 std_experimental_allocator_showcase.html,
|
||||||
`std.experimental.allocator.showcase`).)
|
`std.experimental.allocator.building_blocks.showcase`).)
|
||||||
|
|
||||||
$(BOOKTABLE,
|
$(BOOKTABLE,
|
||||||
$(TR $(TH Allocator$(BR)) $(TH Description))
|
$(TR $(TH Allocator$(BR)) $(TH Description))
|
||||||
|
@ -284,7 +284,7 @@ MYREF = $(LINK2 std_experimental_allocator_$2.html, $1)
|
||||||
MYREF2 = $(LINK2 std_experimental_allocator_$2.html#$1, $1)
|
MYREF2 = $(LINK2 std_experimental_allocator_$2.html#$1, $1)
|
||||||
TDC = $(T td nowrap, $(D $1)$+)
|
TDC = $(T td nowrap, $(D $1)$+)
|
||||||
TDC2 = $(T td nowrap, $(D $(MYREF2 $1,$+))$(BR)$(SMALL
|
TDC2 = $(T td nowrap, $(D $(MYREF2 $1,$+))$(BR)$(SMALL
|
||||||
$(D std.experimental.allocator.$2)))
|
$(D std.experimental.allocator.building_blocks.$2)))
|
||||||
TDC3 = $(T td nowrap, $(D $(MYREF2 $1,$+)))
|
TDC3 = $(T td nowrap, $(D $(MYREF2 $1,$+)))
|
||||||
RES = $(I result)
|
RES = $(I result)
|
||||||
POST = $(BR)$(SMALL $(I Post:) $(BLUE $(D $0)))
|
POST = $(BR)$(SMALL $(I Post:) $(BLUE $(D $0)))
|
||||||
|
@ -293,19 +293,19 @@ POST = $(BR)$(SMALL $(I Post:) $(BLUE $(D $0)))
|
||||||
module std.experimental.allocator.building_blocks;
|
module std.experimental.allocator.building_blocks;
|
||||||
|
|
||||||
public import
|
public import
|
||||||
std.experimental.allocator.affix_allocator,
|
std.experimental.allocator.building_blocks.affix_allocator,
|
||||||
std.experimental.allocator.allocator_list,
|
std.experimental.allocator.building_blocks.allocator_list,
|
||||||
std.experimental.allocator.bucketizer,
|
std.experimental.allocator.building_blocks.bucketizer,
|
||||||
std.experimental.allocator.fallback_allocator,
|
std.experimental.allocator.building_blocks.fallback_allocator,
|
||||||
std.experimental.allocator.free_list,
|
std.experimental.allocator.building_blocks.free_list,
|
||||||
std.experimental.allocator.free_tree,
|
std.experimental.allocator.building_blocks.free_tree,
|
||||||
std.experimental.allocator.gc_allocator,
|
std.experimental.allocator.gc_allocator,
|
||||||
std.experimental.allocator.bitmapped_block,
|
std.experimental.allocator.building_blocks.bitmapped_block,
|
||||||
std.experimental.allocator.kernighan_ritchie,
|
std.experimental.allocator.building_blocks.kernighan_ritchie,
|
||||||
std.experimental.allocator.mallocator,
|
std.experimental.allocator.mallocator,
|
||||||
std.experimental.allocator.mmap_allocator,
|
std.experimental.allocator.mmap_allocator,
|
||||||
std.experimental.allocator.null_allocator,
|
std.experimental.allocator.building_blocks.null_allocator,
|
||||||
std.experimental.allocator.quantizer,
|
std.experimental.allocator.building_blocks.quantizer,
|
||||||
std.experimental.allocator.region,
|
std.experimental.allocator.building_blocks.region,
|
||||||
std.experimental.allocator.segregator,
|
std.experimental.allocator.building_blocks.segregator,
|
||||||
std.experimental.allocator.stats_collector;
|
std.experimental.allocator.building_blocks.stats_collector;
|
|
@ -1,4 +1,4 @@
|
||||||
module std.experimental.allocator.quantizer;
|
module std.experimental.allocator.building_blocks.quantizer;
|
||||||
|
|
||||||
import std.experimental.allocator.common;
|
import std.experimental.allocator.common;
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ struct Quantizer(ParentAllocator, alias roundingFunction)
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.free_tree : FreeTree;
|
import std.experimental.allocator.building_blocks.free_tree : FreeTree;
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
// Quantize small allocations to a multiple of cache line, large ones to a
|
// Quantize small allocations to a multiple of cache line, large ones to a
|
||||||
// multiple of page size
|
// multiple of page size
|
|
@ -1,7 +1,7 @@
|
||||||
module std.experimental.allocator.region;
|
module std.experimental.allocator.building_blocks.region;
|
||||||
|
|
||||||
import std.experimental.allocator.common;
|
import std.experimental.allocator.common;
|
||||||
import std.experimental.allocator.null_allocator;
|
import std.experimental.allocator.building_blocks.null_allocator;
|
||||||
import std.typecons : Flag, Yes, No;
|
import std.typecons : Flag, Yes, No;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -330,7 +330,8 @@ struct Region(ParentAllocator = NullAllocator,
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.mallocator : Mallocator;
|
import std.experimental.allocator.mallocator : Mallocator;
|
||||||
import std.experimental.allocator.allocator_list : AllocatorList;
|
import std.experimental.allocator.building_blocks.allocator_list
|
||||||
|
: AllocatorList;
|
||||||
import std.algorithm : max;
|
import std.algorithm : max;
|
||||||
// Create a scalable list of regions. Each gets at least 1MB at a time by
|
// Create a scalable list of regions. Each gets at least 1MB at a time by
|
||||||
// using malloc.
|
// using malloc.
|
||||||
|
@ -533,10 +534,13 @@ unittest
|
||||||
assert(a1.length == 101);
|
assert(a1.length == 101);
|
||||||
|
|
||||||
// 128KB region, with fallback to the garbage collector.
|
// 128KB region, with fallback to the garbage collector.
|
||||||
import std.experimental.allocator.fallback_allocator : FallbackAllocator;
|
import std.experimental.allocator.building_blocks.fallback_allocator
|
||||||
import std.experimental.allocator.free_list : FreeList;
|
: FallbackAllocator;
|
||||||
|
import std.experimental.allocator.building_blocks.free_list
|
||||||
|
: FreeList;
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.experimental.allocator.bitmapped_block : BitmappedBlock;
|
import std.experimental.allocator.building_blocks.bitmapped_block
|
||||||
|
: BitmappedBlock;
|
||||||
FallbackAllocator!(InSituRegion!(128 * 1024), GCAllocator) r2;
|
FallbackAllocator!(InSituRegion!(128 * 1024), GCAllocator) r2;
|
||||||
const a2 = r2.allocate(102);
|
const a2 = r2.allocate(102);
|
||||||
assert(a2.length == 102);
|
assert(a2.length == 102);
|
|
@ -1,4 +1,4 @@
|
||||||
module std.experimental.allocator.scoped_allocator;
|
module std.experimental.allocator.building_blocks.scoped_allocator;
|
||||||
|
|
||||||
import std.experimental.allocator.common;
|
import std.experimental.allocator.common;
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ struct ScopedAllocator(ParentAllocator)
|
||||||
testAllocator!(() => ScopedAllocator());
|
testAllocator!(() => ScopedAllocator());
|
||||||
}
|
}
|
||||||
|
|
||||||
private import std.experimental.allocator.affix_allocator : AffixAllocator;
|
private import std.experimental.allocator.building_blocks.affix_allocator
|
||||||
|
: AffixAllocator;
|
||||||
private import std.traits : hasMember;
|
private import std.traits : hasMember;
|
||||||
|
|
||||||
private struct Node
|
private struct Node
|
|
@ -1,4 +1,4 @@
|
||||||
module std.experimental.allocator.segregator;
|
module std.experimental.allocator.building_blocks.segregator;
|
||||||
|
|
||||||
import std.experimental.allocator.common;
|
import std.experimental.allocator.common;
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ struct Segregator(size_t threshold, SmallAllocator, LargeAllocator)
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.free_list : FreeList;
|
import std.experimental.allocator.building_blocks.free_list : FreeList;
|
||||||
import std.experimental.allocator.mallocator : Mallocator;
|
import std.experimental.allocator.mallocator : Mallocator;
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
alias A =
|
alias A =
|
||||||
|
@ -347,7 +347,7 @@ template Segregator(Args...) if (Args.length > 3)
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.free_list : FreeList;
|
import std.experimental.allocator.building_blocks.free_list : FreeList;
|
||||||
import std.experimental.allocator.mallocator : Mallocator;
|
import std.experimental.allocator.mallocator : Mallocator;
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
alias A =
|
alias A =
|
|
@ -1,4 +1,4 @@
|
||||||
module std.experimental.allocator.stats_collector;
|
module std.experimental.allocator.building_blocks.stats_collector;
|
||||||
|
|
||||||
import std.experimental.allocator.common;
|
import std.experimental.allocator.common;
|
||||||
|
|
||||||
|
@ -643,7 +643,7 @@ public:
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.experimental.allocator.free_list : FreeList;
|
import std.experimental.allocator.building_blocks.free_list : FreeList;
|
||||||
alias Allocator = StatsCollector!(GCAllocator, Options.all, Options.all);
|
alias Allocator = StatsCollector!(GCAllocator, Options.all, Options.all);
|
||||||
|
|
||||||
Allocator alloc;
|
Allocator alloc;
|
||||||
|
@ -693,7 +693,7 @@ unittest
|
||||||
}
|
}
|
||||||
|
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.experimental.allocator.free_list : FreeList;
|
import std.experimental.allocator.building_blocks.free_list : FreeList;
|
||||||
test!(StatsCollector!(GCAllocator, Options.all, Options.all));
|
test!(StatsCollector!(GCAllocator, Options.all, Options.all));
|
||||||
test!(StatsCollector!(FreeList!(GCAllocator, 128), Options.all,
|
test!(StatsCollector!(FreeList!(GCAllocator, 128), Options.all,
|
||||||
Options.all));
|
Options.all));
|
||||||
|
@ -717,6 +717,6 @@ unittest
|
||||||
a.deallocate(b3);
|
a.deallocate(b3);
|
||||||
}
|
}
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
import std.experimental.allocator.free_list : FreeList;
|
import std.experimental.allocator.building_blocks.free_list : FreeList;
|
||||||
test!(StatsCollector!(GCAllocator, 0, 0));
|
test!(StatsCollector!(GCAllocator, 0, 0));
|
||||||
}
|
}
|
|
@ -559,7 +559,7 @@ bool alignedReallocate(Allocator)(ref Allocator alloc,
|
||||||
/**
|
/**
|
||||||
Forwards each of the methods in `funs` (if defined) to `member`.
|
Forwards each of the methods in `funs` (if defined) to `member`.
|
||||||
*/
|
*/
|
||||||
package string forwardToMember(string member, string[] funs...)
|
/*package*/ string forwardToMember(string member, string[] funs...)
|
||||||
{
|
{
|
||||||
string result = " import std.traits : hasMember, ParameterTypeTuple;\n";
|
string result = " import std.traits : hasMember, ParameterTypeTuple;\n";
|
||||||
foreach (fun; funs)
|
foreach (fun; funs)
|
||||||
|
|
|
@ -50,25 +50,22 @@ Source: $(PHOBOSSRC std/experimental/_allocator)
|
||||||
module std.experimental.allocator;
|
module std.experimental.allocator;
|
||||||
|
|
||||||
public import
|
public import
|
||||||
std.experimental.allocator.affix_allocator,
|
//std.experimental.allocator.building_blocks,
|
||||||
std.experimental.allocator.allocator_list,
|
|
||||||
std.experimental.allocator.bucketizer,
|
|
||||||
std.experimental.allocator.common,
|
std.experimental.allocator.common,
|
||||||
std.experimental.allocator.fallback_allocator,
|
|
||||||
std.experimental.allocator.free_list,
|
|
||||||
std.experimental.allocator.gc_allocator,
|
|
||||||
std.experimental.allocator.bitmapped_block,
|
|
||||||
std.experimental.allocator.mallocator,
|
|
||||||
std.experimental.allocator.mmap_allocator,
|
|
||||||
std.experimental.allocator.null_allocator,
|
|
||||||
std.experimental.allocator.region,
|
|
||||||
std.experimental.allocator.segregator,
|
|
||||||
std.experimental.allocator.stats_collector,
|
|
||||||
std.experimental.allocator.typed;
|
std.experimental.allocator.typed;
|
||||||
|
|
||||||
// Example in the synopsis above
|
// Example in the synopsis above
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
|
import std.experimental.allocator.building_blocks.free_list : FreeList;
|
||||||
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
|
import std.experimental.allocator.building_blocks.segregator : Segregator;
|
||||||
|
import std.experimental.allocator.building_blocks.bucketizer : Bucketizer;
|
||||||
|
import std.experimental.allocator.building_blocks.allocator_list
|
||||||
|
: AllocatorList;
|
||||||
|
import std.experimental.allocator.building_blocks.bitmapped_block
|
||||||
|
: BitmappedBlock;
|
||||||
|
|
||||||
alias FList = FreeList!(GCAllocator, 0, unbounded);
|
alias FList = FreeList!(GCAllocator, 0, unbounded);
|
||||||
alias A = Segregator!(
|
alias A = Segregator!(
|
||||||
8, FreeList!(GCAllocator, 0, 8),
|
8, FreeList!(GCAllocator, 0, 8),
|
||||||
|
@ -231,7 +228,7 @@ in turn uses the garbage collected heap.
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
// Install a new allocator that is faster for 128-byte allocations.
|
// Install a new allocator that is faster for 128-byte allocations.
|
||||||
import std.experimental.allocator.free_list : FreeList;
|
import std.experimental.allocator.building_blocks.free_list : FreeList;
|
||||||
import std.experimental.allocator.gc_allocator : GCAllocator;
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
auto oldAllocator = theAllocator;
|
auto oldAllocator = theAllocator;
|
||||||
scope(exit) theAllocator = oldAllocator;
|
scope(exit) theAllocator = oldAllocator;
|
||||||
|
@ -1049,7 +1046,7 @@ unittest
|
||||||
assert(a.deallocate(b));
|
assert(a.deallocate(b));
|
||||||
|
|
||||||
// The in-situ region must be used by pointer
|
// The in-situ region must be used by pointer
|
||||||
import std.experimental.allocator.region : InSituRegion;
|
import std.experimental.allocator.building_blocks.region : InSituRegion;
|
||||||
auto r = InSituRegion!1024();
|
auto r = InSituRegion!1024();
|
||||||
a = allocatorObject(&r);
|
a = allocatorObject(&r);
|
||||||
b = a.allocate(200);
|
b = a.allocate(200);
|
||||||
|
|
|
@ -7,9 +7,9 @@ facilities, or import individual heap building blocks and assemble them.
|
||||||
*/
|
*/
|
||||||
module std.experimental.allocator.showcase;
|
module std.experimental.allocator.showcase;
|
||||||
|
|
||||||
import std.experimental.allocator.fallback_allocator,
|
import std.experimental.allocator.building_blocks.fallback_allocator,
|
||||||
std.experimental.allocator.gc_allocator,
|
std.experimental.allocator.gc_allocator,
|
||||||
std.experimental.allocator.region;
|
std.experimental.allocator.building_blocks.region;
|
||||||
import std.traits : hasMember;
|
import std.traits : hasMember;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,8 +62,10 @@ auto mmapRegionList(size_t bytesPerRegion)
|
||||||
{
|
{
|
||||||
size_t bytesPerRegion;
|
size_t bytesPerRegion;
|
||||||
private import std.algorithm : max;
|
private import std.algorithm : max;
|
||||||
private import std.experimental.allocator.region : Region;
|
private import std.experimental.allocator.building_blocks.region
|
||||||
private import std.experimental.allocator.mmap_allocator : MmapAllocator;
|
: Region;
|
||||||
|
private import std.experimental.allocator.mmap_allocator
|
||||||
|
: MmapAllocator;
|
||||||
this(size_t n)
|
this(size_t n)
|
||||||
{
|
{
|
||||||
bytesPerRegion = n;
|
bytesPerRegion = n;
|
||||||
|
@ -73,8 +75,10 @@ auto mmapRegionList(size_t bytesPerRegion)
|
||||||
return Region!MmapAllocator(max(n, bytesPerRegion));
|
return Region!MmapAllocator(max(n, bytesPerRegion));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
import std.experimental.allocator.allocator_list : AllocatorList;
|
import std.experimental.allocator.building_blocks.allocator_list
|
||||||
import std.experimental.allocator.null_allocator : NullAllocator;
|
: AllocatorList;
|
||||||
|
import std.experimental.allocator.building_blocks.null_allocator
|
||||||
|
: NullAllocator;
|
||||||
auto shop = Factory(bytesPerRegion);
|
auto shop = Factory(bytesPerRegion);
|
||||||
return AllocatorList!(Factory, NullAllocator)(shop);
|
return AllocatorList!(Factory, NullAllocator)(shop);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue