Fix ChoppedVector to properly use GC.addRange for allocated memory.
This commit is contained in:
parent
9bf0875778
commit
92c6783ef3
|
@ -31,6 +31,8 @@ struct StdoutRange {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) {
|
struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) {
|
||||||
|
import core.memory : GC;
|
||||||
|
|
||||||
static assert(nextPOT(CHUNK_SIZE) == CHUNK_SIZE,
|
static assert(nextPOT(CHUNK_SIZE) == CHUNK_SIZE,
|
||||||
"CHUNK_SIZE must be a power of two for performance reasons.");
|
"CHUNK_SIZE must be a power of two for performance reasons.");
|
||||||
|
|
||||||
|
@ -62,8 +64,10 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) {
|
||||||
void clear()
|
void clear()
|
||||||
@nogc {
|
@nogc {
|
||||||
() @trusted {
|
() @trusted {
|
||||||
foreach (i; 0 .. m_chunkCount)
|
foreach (i; 0 .. m_chunkCount) {
|
||||||
|
GC.removeRange(m_chunks[i]);
|
||||||
free(m_chunks[i]);
|
free(m_chunks[i]);
|
||||||
|
}
|
||||||
free(m_chunks.ptr);
|
free(m_chunks.ptr);
|
||||||
} ();
|
} ();
|
||||||
m_chunkCount = 0;
|
m_chunkCount = 0;
|
||||||
|
@ -119,7 +123,11 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (m_chunkCount <= chunkidx) {
|
while (m_chunkCount <= chunkidx) {
|
||||||
() @trusted { m_chunks[m_chunkCount++] = cast(ChunkPtr)calloc(chunkSize, T.sizeof); } ();
|
() @trusted {
|
||||||
|
auto ptr = cast(ChunkPtr)calloc(chunkSize, T.sizeof);
|
||||||
|
GC.addRange(ptr, chunkSize * T.sizeof);
|
||||||
|
m_chunks[m_chunkCount++] = ptr;
|
||||||
|
} ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +137,10 @@ struct AlgebraicChoppedVector(TCommon, TSpecific...)
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
import std.meta : AliasSeq;
|
import std.meta : AliasSeq;
|
||||||
|
|
||||||
union U { mixin fields!0; }
|
union U {
|
||||||
|
typeof(null) none;
|
||||||
|
mixin fields!0;
|
||||||
|
}
|
||||||
alias FieldType = TaggedAlgebraic!U;
|
alias FieldType = TaggedAlgebraic!U;
|
||||||
static struct FullField {
|
static struct FullField {
|
||||||
TCommon common;
|
TCommon common;
|
||||||
|
|
Loading…
Reference in a new issue