Esempio n. 1
0
void TestTrackingAllocatorSize(void)
{
	CTrackingAllocator	cTracking;
	CMemoryAllocator	cMemory;
	void*				pv1;
	void*				pv2;
	void*				pv3;
	void*				pv4;

	cMemory.Init();
	cTracking.Init(&cMemory);
	AssertInt(0, cTracking.AllocatedSize());

	pv1 = cTracking.Malloc(100);
	AssertInt(100, cTracking.AllocatedSize());

	pv2 = cTracking.Malloc(200);
	AssertInt(300, cTracking.AllocatedSize());

	pv3 = cTracking.Malloc(50);
	AssertInt(350, cTracking.AllocatedSize());

	pv4 = cTracking.Realloc(pv3, 1000);
	AssertInt(1300, cTracking.AllocatedSize());

	cTracking.Free(pv1);
	AssertInt(1200, cTracking.AllocatedSize());

	cTracking.Free(pv2);
	AssertInt(1000, cTracking.AllocatedSize());

	cTracking.Free(pv4);
	AssertInt(0, cTracking.AllocatedSize());

	cTracking.Kill();
	cMemory.Kill();
}
Esempio n. 2
0
void TestIndexTreeBlockMemoryRemoveResize(void)
{
	CIndexTreeBlockMemory	cIndex;
	long long				li;
	CMemoryAllocator		cMemoryAlloc;
	CTrackingAllocator		cTrackingAlloc;
	int						iExpectedRootSize;

	cMemoryAlloc.Init();
	cTrackingAlloc.Init(&cMemoryAlloc);

	cIndex.Init(&cTrackingAlloc);
	AssertInt(1, cIndex.CountAllocatedNodes());
	AssertInt(0, cIndex.RecurseSize());
	AssertInt(12, cIndex.SizeofNode());
	AssertInt(4, cIndex.SizeofNodePtr());
	iExpectedRootSize = cIndex.CalculateRootNodeSize();
	AssertInt(1036, iExpectedRootSize);
	AssertInt(1036, cTrackingAlloc.AllocatedSize());

	li = 0x77LL; cIndex.Put("M", &li, sizeof(long long));
	AssertInt(2, cIndex.CountAllocatedNodes());
	AssertInt(1, cIndex.RecurseSize());
	AssertInt(1056, iExpectedRootSize + sizeof(CIndexTreeNodeMemory) + sizeof(long long));
	AssertInt(1056, cTrackingAlloc.AllocatedSize());

	li = 0x88LL; cIndex.Put("MA", &li, sizeof(long long));
	AssertInt(1080, cTrackingAlloc.AllocatedSize());
	li = 0x99LL; cIndex.Put("MC", &li, sizeof(long long));
	AssertInt(4, cIndex.CountAllocatedNodes());
	AssertInt(3, cIndex.RecurseSize());
	AssertInt(1108, cTrackingAlloc.AllocatedSize());

	li = 0xaaLL; cIndex.Put("MB", &li, sizeof(long long));
	AssertInt(5, cIndex.CountAllocatedNodes());
	AssertInt(4, cIndex.RecurseSize());
	AssertInt(1128, cTrackingAlloc.AllocatedSize());

	li = 0xbbLL; cIndex.Put("MBP", &li, sizeof(long long));
	AssertInt(6, cIndex.CountAllocatedNodes());
	AssertInt(5, cIndex.RecurseSize());
	AssertInt(5, cIndex.NumElements());
	AssertInt(1152, cTrackingAlloc.AllocatedSize());

	AssertLongLongInt(0xaaLL, *((long long*)cIndex.Get("MB")));
	cIndex.Remove("MB");
	AssertInt(6, cIndex.CountAllocatedNodes());
	AssertInt(4, cIndex.RecurseSize());
	AssertInt(4, cIndex.NumElements());
	AssertInt(1152, cTrackingAlloc.AllocatedSize());
	AssertNull(cIndex.Get("MB"));

	AssertLongLongInt(0xbbLL, *((long long*)cIndex.Get("MBP")));
	cIndex.Remove("MBP");
	AssertInt(4, cIndex.CountAllocatedNodes());
	AssertInt(3, cIndex.RecurseSize());
	AssertInt(3, cIndex.NumElements());
	AssertInt(1108, cTrackingAlloc.AllocatedSize());
	AssertNull(cIndex.Get("MBP"));

	AssertLongLongInt(0x99LL, *((long long*)cIndex.Get("MC")));
	AssertLongLongInt(0x88LL, *((long long*)cIndex.Get("MA")));
	cIndex.Remove("MA");
	AssertInt(3, cIndex.CountAllocatedNodes());
	AssertInt(2, cIndex.RecurseSize());
	AssertInt(2, cIndex.NumElements());
	AssertInt(1080, cTrackingAlloc.AllocatedSize());
	AssertNull(cIndex.Get("MA"));

	AssertLongLongInt(0x99LL, *((long long*)cIndex.Get("MC")));
	cIndex.Remove("MC");
	AssertInt(2, cIndex.CountAllocatedNodes());
	AssertInt(1, cIndex.RecurseSize());
	AssertInt(1, cIndex.NumElements());
	AssertInt(1056, cTrackingAlloc.AllocatedSize());
	AssertNull(cIndex.Get("MC"));

	AssertLongLongInt(0x77LL, *((long long*)cIndex.Get("M")));
	cIndex.Remove("M");
	AssertInt(1, cIndex.CountAllocatedNodes());
	AssertInt(0, cIndex.RecurseSize());
	AssertInt(0, cIndex.NumElements());
	AssertInt(1036, cTrackingAlloc.AllocatedSize());
	AssertNull(cIndex.Get("M"));

	cIndex.Kill();
	cTrackingAlloc.Kill();
	cMemoryAlloc.Kill();
}