|
@@ -62,9 +62,9 @@ using SLAlloc = SegregatedListsAllocatorBuilder<SegregatedListsAllocatorBuilderC
|
|
|
template<typename TAlloc>
|
|
template<typename TAlloc>
|
|
|
static void printAllocatorBuilder(const TAlloc& sl)
|
|
static void printAllocatorBuilder(const TAlloc& sl)
|
|
|
{
|
|
{
|
|
|
- HeapAllocator<U8> alloc(allocAligned, nullptr);
|
|
|
|
|
|
|
+ HeapMemoryPool pool(allocAligned, nullptr);
|
|
|
|
|
|
|
|
- StringListRaii list(alloc);
|
|
|
|
|
|
|
+ StringListRaii list(&pool);
|
|
|
sl.printFreeBlocks(list);
|
|
sl.printFreeBlocks(list);
|
|
|
|
|
|
|
|
if(list.isEmpty())
|
|
if(list.isEmpty())
|
|
@@ -72,12 +72,12 @@ static void printAllocatorBuilder(const TAlloc& sl)
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- StringRaii str(alloc);
|
|
|
|
|
|
|
+ StringRaii str(&pool);
|
|
|
list.join("", str);
|
|
list.join("", str);
|
|
|
printf("%s\n", str.cstr());
|
|
printf("%s\n", str.cstr());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-template<Bool T_VALIDATE, U32 T_ITERATIONS, Bool T_STATS>
|
|
|
|
|
|
|
+template<Bool kValidate, U32 kIterationCount, Bool kStats>
|
|
|
static void fuzzyTest()
|
|
static void fuzzyTest()
|
|
|
{
|
|
{
|
|
|
class Alloc
|
|
class Alloc
|
|
@@ -91,13 +91,13 @@ static void fuzzyTest()
|
|
|
|
|
|
|
|
SLAlloc sl;
|
|
SLAlloc sl;
|
|
|
std::vector<Alloc> allocs;
|
|
std::vector<Alloc> allocs;
|
|
|
- allocs.reserve(T_ITERATIONS);
|
|
|
|
|
|
|
+ allocs.reserve(kIterationCount);
|
|
|
|
|
|
|
|
const Second start = HighRezTimer::getCurrentTime();
|
|
const Second start = HighRezTimer::getCurrentTime();
|
|
|
F64 avgFragmentation = 0.0f;
|
|
F64 avgFragmentation = 0.0f;
|
|
|
F64 maxFragmetation = 0.0f;
|
|
F64 maxFragmetation = 0.0f;
|
|
|
|
|
|
|
|
- for(U32 i = 0; i < T_ITERATIONS; ++i)
|
|
|
|
|
|
|
+ for(U32 i = 0; i < kIterationCount; ++i)
|
|
|
{
|
|
{
|
|
|
const Bool doAllocation = (getRandom() % 2) == 0;
|
|
const Bool doAllocation = (getRandom() % 2) == 0;
|
|
|
if(doAllocation)
|
|
if(doAllocation)
|
|
@@ -123,15 +123,15 @@ static void fuzzyTest()
|
|
|
sl.free(alloc.m_chunk, alloc.m_address, alloc.m_size);
|
|
sl.free(alloc.m_chunk, alloc.m_address, alloc.m_size);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(T_STATS)
|
|
|
|
|
|
|
+ if(kStats)
|
|
|
{
|
|
{
|
|
|
const F64 f = sl.computeExternalFragmentation();
|
|
const F64 f = sl.computeExternalFragmentation();
|
|
|
- avgFragmentation += f / F64(T_ITERATIONS);
|
|
|
|
|
|
|
+ avgFragmentation += f / F64(kIterationCount);
|
|
|
maxFragmetation = max(maxFragmetation, f);
|
|
maxFragmetation = max(maxFragmetation, f);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// printAllocatorBuilder(sl);
|
|
// printAllocatorBuilder(sl);
|
|
|
- if(T_VALIDATE)
|
|
|
|
|
|
|
+ if(kValidate)
|
|
|
{
|
|
{
|
|
|
ANKI_TEST_EXPECT_NO_ERR(sl.validate());
|
|
ANKI_TEST_EXPECT_NO_ERR(sl.validate());
|
|
|
}
|
|
}
|
|
@@ -143,12 +143,12 @@ static void fuzzyTest()
|
|
|
sl.free(alloc.m_chunk, alloc.m_address, alloc.m_size);
|
|
sl.free(alloc.m_chunk, alloc.m_address, alloc.m_size);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(T_STATS)
|
|
|
|
|
|
|
+ if(kStats)
|
|
|
{
|
|
{
|
|
|
const Second end = HighRezTimer::getCurrentTime();
|
|
const Second end = HighRezTimer::getCurrentTime();
|
|
|
const Second dt = end - start;
|
|
const Second dt = end - start;
|
|
|
ANKI_TEST_LOGI("Operations/sec %f. Avg external fragmentation %f. Max external fragmentation %f",
|
|
ANKI_TEST_LOGI("Operations/sec %f. Avg external fragmentation %f. Max external fragmentation %f",
|
|
|
- F64(T_ITERATIONS) / dt, avgFragmentation, maxFragmetation);
|
|
|
|
|
|
|
+ F64(kIterationCount) / dt, avgFragmentation, maxFragmetation);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|