Deprecate MmapPool for the standard build

Mallocator is the default allocator now and should be used instead.
This commit is contained in:
Eugen Wissner 2018-03-06 05:29:15 +01:00
parent fbbdb36853
commit 54bcec216e

View File

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** /*
* Native allocator for Posix and Windows. * Native allocator for Posix and Windows.
* *
* Copyright: Eugene Wissner 2016-2017. * Copyright: Eugene Wissner 2016-2017.
@ -82,7 +82,7 @@ else version (Windows)
} }
} }
/** /*
* This allocator allocates memory in regions (multiple of 64 KB for example). * This allocator allocates memory in regions (multiple of 64 KB for example).
* Each region is then splitted in blocks. So it doesn't request the memory * Each region is then splitted in blocks. So it doesn't request the memory
* from the operating system on each call, but only if there are no large * from the operating system on each call, but only if there are no large
@ -106,6 +106,7 @@ else version (Windows)
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* </pre> * </pre>
*/ */
deprecated("Use tanya.memory.mallocator instead")
final class MmapPool : Allocator final class MmapPool : Allocator
{ {
version (none) version (none)
@ -126,7 +127,7 @@ final class MmapPool : Allocator
} }
} }
/** /*
* Allocates $(D_PARAM size) bytes of memory. * Allocates $(D_PARAM size) bytes of memory.
* *
* Params: * Params:
@ -155,8 +156,7 @@ final class MmapPool : Allocator
return data is null ? null : data[0 .. size]; return data is null ? null : data[0 .. size];
} }
/// version (TanyaNative) @nogc nothrow pure unittest
nothrow unittest
{ {
auto p = MmapPool.instance.allocate(20); auto p = MmapPool.instance.allocate(20);
assert(p); assert(p);
@ -167,7 +167,7 @@ final class MmapPool : Allocator
} }
// Issue 245: https://issues.caraus.io/issues/245. // Issue 245: https://issues.caraus.io/issues/245.
private @nogc unittest version (TanyaNative) @nogc nothrow pure unittest
{ {
// allocate() check. // allocate() check.
size_t tooMuchMemory = size_t.max size_t tooMuchMemory = size_t.max
@ -245,7 +245,7 @@ final class MmapPool : Allocator
block.next = block.next.next; block.next = block.next.next;
} }
/** /*
* Deallocates a memory block. * Deallocates a memory block.
* *
* Params: * Params:
@ -299,15 +299,14 @@ final class MmapPool : Allocator
return true; return true;
} }
/// version (TanyaNative) @nogc nothrow pure unittest
nothrow unittest
{ {
auto p = MmapPool.instance.allocate(20); auto p = MmapPool.instance.allocate(20);
assert(MmapPool.instance.deallocate(p)); assert(MmapPool.instance.deallocate(p));
} }
/** /*
* Reallocates a memory block in place if possible or returns * Reallocates a memory block in place if possible or returns
* $(D_KEYWORD false). This function cannot be used to allocate or * $(D_KEYWORD false). This function cannot be used to allocate or
* deallocate memory, so if $(D_PARAM p) is $(D_KEYWORD null) or * deallocate memory, so if $(D_PARAM p) is $(D_KEYWORD null) or
@ -383,8 +382,7 @@ final class MmapPool : Allocator
return true; return true;
} }
/// version (TanyaNative) @nogc nothrow pure unittest
nothrow unittest
{ {
void[] p; void[] p;
assert(!MmapPool.instance.reallocateInPlace(p, 5)); assert(!MmapPool.instance.reallocateInPlace(p, 5));
@ -408,7 +406,7 @@ final class MmapPool : Allocator
MmapPool.instance.deallocate(p); MmapPool.instance.deallocate(p);
} }
/** /*
* Increases or decreases the size of a memory block. * Increases or decreases the size of a memory block.
* *
* Params: * Params:
@ -449,8 +447,7 @@ final class MmapPool : Allocator
return true; return true;
} }
/// version (TanyaNative) @nogc nothrow pure unittest
nothrow unittest
{ {
void[] p; void[] p;
MmapPool.instance.reallocate(p, 10 * int.sizeof); MmapPool.instance.reallocate(p, 10 * int.sizeof);
@ -514,7 +511,7 @@ final class MmapPool : Allocator
return instance_; return instance_;
} }
/** /*
* Static allocator instance and initializer. * Static allocator instance and initializer.
* *
* Returns: Global $(D_PSYMBOL MmapPool) instance. * Returns: Global $(D_PSYMBOL MmapPool) instance.
@ -524,8 +521,7 @@ final class MmapPool : Allocator
return (cast(GetPureInstance!MmapPool) &instantiate)(); return (cast(GetPureInstance!MmapPool) &instantiate)();
} }
/// version (TanyaNative) @nogc nothrow pure unittest
nothrow unittest
{ {
assert(instance is instance); assert(instance is instance);
} }
@ -622,7 +618,7 @@ final class MmapPool : Allocator
/ pageSize * pageSize + pageSize; / pageSize * pageSize + pageSize;
} }
/** /*
* Returns: Alignment offered. * Returns: Alignment offered.
*/ */
@property uint alignment() shared const pure nothrow @safe @nogc @property uint alignment() shared const pure nothrow @safe @nogc
@ -630,7 +626,7 @@ final class MmapPool : Allocator
return alignment_; return alignment_;
} }
private nothrow @nogc unittest version (TanyaNative) @nogc nothrow pure unittest
{ {
assert(MmapPool.instance.alignment == MmapPool.alignment_); assert(MmapPool.instance.alignment == MmapPool.alignment_);
} }
@ -661,9 +657,11 @@ final class MmapPool : Allocator
private alias Block = shared BlockEntry*; private alias Block = shared BlockEntry*;
} }
version (TanyaNative):
// A lot of allocations/deallocations, but it is the minimum caused a // A lot of allocations/deallocations, but it is the minimum caused a
// segmentation fault because MmapPool reallocateInPlace moves a block wrong. // segmentation fault because MmapPool reallocateInPlace moves a block wrong.
private @nogc unittest @nogc nothrow pure unittest
{ {
auto a = MmapPool.instance.allocate(16); auto a = MmapPool.instance.allocate(16);
auto d = MmapPool.instance.allocate(16); auto d = MmapPool.instance.allocate(16);