Esempio n. 1
0
void TestMemoryAllocatorFree(void)
{
	MemoryInit();

	CMemoryAllocator		cAlloc;
	CConstructorTestClass*	pcTest;

	gcConstructors.Add<CConstructorTestClass>("CConstructorTestClass");

	cAlloc.Init();
	AssertInt(0, cAlloc.GetMemory()->NumElements());

	pcTest = (CConstructorTestClass*)gcConstructors.Construct("CConstructorTestClass", &cAlloc);
	AssertInt(1, cAlloc.GetMemory()->NumElements());

	pcTest->k = 7;
	AssertInt(3, pcTest->Method1());
	AssertInt(7, pcTest->k);
	
	cAlloc.Free(pcTest);
	AssertInt(0, cAlloc.GetMemory()->NumElements());

	cAlloc.Kill();

	MemoryKill();
}
Esempio n. 2
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();
}
void TestIndexTreeMemoryRemoveResize(void)
{
	CIndexTreeMemory	cIndex;
	long long			li;
	CMemoryAllocator	cMemoryAlloc;
	CCountingAllocator	cTrackingAlloc;
	int					iExpectedRootSize;

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

	cIndex.Init(&cTrackingAlloc);
	AssertInt(1, cIndex.CountAllocatedNodes());
	AssertInt(0, cIndex.RecurseSize());
	AssertInt(16, cIndex.SizeofNode());
	AssertInt(4, cIndex.SizeofNodePtr());
	iExpectedRootSize = cIndex.CalculateRootNodeSize();
	AssertInt(1040, iExpectedRootSize);
	AssertInt(1040, cTrackingAlloc.AllocatedUserSize());

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

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

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

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

	AssertLongLongInt(0xaaLL, *((long long*)cIndex.Get("MB")));
	cIndex.Remove("MB");
	AssertInt(6, cIndex.CountAllocatedNodes());
	AssertInt(4, cIndex.RecurseSize());
	AssertInt(4, cIndex.NumElements());
	AssertInt(1176, cTrackingAlloc.AllocatedUserSize());
	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(1124, cTrackingAlloc.AllocatedUserSize());
	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(1092, cTrackingAlloc.AllocatedUserSize());
	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(1064, cTrackingAlloc.AllocatedUserSize());
	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(1040, cTrackingAlloc.AllocatedUserSize());
	AssertNull(cIndex.Get("M"));

	cIndex.Kill();
	cTrackingAlloc.Kill();
	cMemoryAlloc.Kill();
}
Esempio n. 4
0
void TestMemoryAllocatorReadWrite(void)
{
	MemoryInit();

	CMemoryAllocator		cAlloc;
	CFileBasic				cFile;
	CMemoryAllocator		cAllocIn;
	int						i;
	SMemoryParams			sParams;
	SMemoryFreeListParams*	psBlockParams;

	cFile.Init(MemoryFile());
	cFile.Open(EFM_ReadWrite_Create);

	cFile.WriteInt(789);

	cAlloc.Init(16, FALSE);
	cAlloc.GetMemory()->AddParamBlock(24  , 16  , 32*32);
	cAlloc.GetMemory()->AddParamBlock(32  , 24  , 28*32);
	cAlloc.GetMemory()->AddParamBlock(40  , 32  , 24*32);

	AssertTrue(cAlloc.Write(&cFile));

	cFile.WriteInt(124);

	cFile.Close();
	cAlloc.Kill();

	cFile.Open(EFM_Read);

	cFile.ReadInt(&i);
	AssertInt(789, i);

	AssertTrue(cAllocIn.Read(&cFile));

	cFile.ReadInt(&i);
	AssertInt(124, i);

	AssertInt(16, cAllocIn.GetMemory()->ByteSize());
	cAllocIn.GetMemory()->GetParams(&sParams);
	AssertInt(16, sParams.iDefaultAlignment);
	AssertInt(56, sParams.uiFreeListSizeLimit);
	AssertInt(3, sParams.iFreeListParams);

	psBlockParams = cAllocIn.GetMemory()->GetFreeListParams(0);
	AssertNotNull(psBlockParams);
	AssertInt(32*32, psBlockParams->iChunkSize);
	AssertInt(17, psBlockParams->iMinElementSize);
	AssertInt(24, psBlockParams->iMaxElementSize);

	psBlockParams = cAllocIn.GetMemory()->GetFreeListParams(1);
	AssertNotNull(psBlockParams);
	AssertInt(28*32, psBlockParams->iChunkSize);
	AssertInt(25, psBlockParams->iMinElementSize);
	AssertInt(32, psBlockParams->iMaxElementSize);

	psBlockParams = cAllocIn.GetMemory()->GetFreeListParams(2);
	AssertNotNull(psBlockParams);
	AssertInt(24*32, psBlockParams->iChunkSize);
	AssertInt(33, psBlockParams->iMinElementSize);
	AssertInt(40, psBlockParams->iMaxElementSize);

	psBlockParams = cAllocIn.GetMemory()->GetFreeListParams(3);
	AssertNull(psBlockParams);

	MemoryKill();
}
TIMM_OSAL_ERRORTYPE CComponentDispatcherMarshalMemFreeHandle::Process(void* pMessage)
{
    COMXComponent *pComp;
    marshalMemAllocMessage_t* marshalCtx = ((marshalMemAllocMessage_t *)((systemMessage_t *)pMessage)->pPayload);

    pComp = (COMXComponent*)dispatcher->GetOMXComponentSlot(marshalCtx->nComponentId);

    if (NULL == pComp)
	{
        MMS_IL_PRINT("Unknown component\n");
        return TIMM_OSAL_ERR_UNKNOWN;
    }

    if (pComp->nMemMarshallingListSz > 0)
	{
        unsigned int i;
        unsigned int nFreeCells = 0;
        unsigned int bMatch = 0;

        for (i = 0; i < pComp->nMemMarshallingListSz; i++)
		{
            if (pComp->pMemMarshalling[i].pA9 == marshalCtx->nPtr)
			{

                if (pComp->tMemMarshallingAllocStrat == MEM_OSAL)
				{
                    free(pComp->pMemMarshalling[i].pA9);
                }
				else if(pComp->tMemMarshallingAllocStrat == MEM_ION_1D)
				{
					CMemoryAllocator* ionAlloc = CMemoryAllocatorFactory::CreateMemoryAllocatorHandle(ION_MemoryAllocatorType);
                    ionAlloc->free(pComp->pMemMarshalling[i].pA9);
                }
                pComp->pMemMarshalling[i].pA9 = NULL;
                nFreeCells++;
                bMatch = 1;
            }
            else if(pComp->pMemMarshalling[i].pA9 == NULL)
			{
                nFreeCells++;
            }
        }

        if (nFreeCells == pComp->nMemMarshallingListSz)
		{
            pComp->nMemMarshallingListSz = 0;
            free(pComp->pMemMarshalling);
            pComp->pMemMarshalling = NULL;
        }

        if (bMatch)
		{
            MMS_IL_PRINT("0\n");
            return TIMM_OSAL_ERR_NONE;
        } 
		else 
		{
            MMS_IL_PRINT("Component has no associated allocated memory with address %p!\n", marshalCtx->nPtr);
            return TIMM_OSAL_ERR_UNKNOWN;
        }//if (bMatch)
    }//if (pComp->nMemMarshallingListSz > 0)

    MMS_IL_PRINT("Component has no associated allocated memory at all!\n");
    return TIMM_OSAL_ERR_UNKNOWN; 
}
TIMM_OSAL_ERRORTYPE CComponentDispatcherMarshalMemDumpHandle::Process(void* pMessage)
{
    TIMM_OSAL_ERRORTYPE error = TIMM_OSAL_ERR_NONE;
    COMXComponent *pComp;
    marshalMemAllocMessage_t* marshalCtx = ((marshalMemAllocMessage_t *)((systemMessage_t *)pMessage)->pPayload);
    void* dataBuffPtr = NULL;
    pComp = (COMXComponent*)dispatcher->GetOMXComponentSlot(marshalCtx->nComponentId);

    ServiceHeaderSaveBuffer_t ServiceHeaderSaveBuffer;

    if (NULL == pComp)
	{
        MMS_IL_PRINT("Unknown component\n");
        return TIMM_OSAL_ERR_UNKNOWN;
    }

    if (pComp->nMemMarshallingListSz <= 0)
	{
        MMS_IL_PRINT("nMemMarshallingListSz is zero! No memory to dump\n");
        return TIMM_OSAL_ERR_NONE;
    }//if (pComp->nMemMarshallingListSz > 0)

    for (unsigned int i = 0; i < pComp->nMemMarshallingListSz; i++)
	{
        if (pComp->pMemMarshalling[i].pA9 == marshalCtx->nPtr)
		{
            CTransferBufferSave2File SaveBuffer;
            if (pComp->tMemMarshallingAllocStrat == MEM_ION_1D)
			{
				CMemoryAllocator* ionAlloc = CMemoryAllocatorFactory::CreateMemoryAllocatorHandle(ION_MemoryAllocatorType);
                // dataBuffPtr = marshalCtx->nPtr;
                dataBuffPtr = (TIMM_OSAL_U8*)ionAlloc->getMappedAddr(marshalCtx->nPtr);
                if (dataBuffPtr == NULL)
				{
                    return TIMM_OSAL_ERR_UNKNOWN;
                }
            }
			else
			{
                dataBuffPtr = (TIMM_OSAL_U8*)marshalCtx->nPtr;
            }// if (pComp->tMemMarshallingAllocStrat == MEM_ION_1D)

            strcpy(ServiceHeaderSaveBuffer.namePrfx,"\0");
            strcpy(ServiceHeaderSaveBuffer.fileExt,"\0");

            error += SaveBuffer.Init(pComp, (unsigned int) marshalCtx->nPtr, marshalCtx->nSize, &ServiceHeaderSaveBuffer);
            error += SaveBuffer.Transfer(dataBuffPtr);

            if (TIMM_OSAL_ERR_NONE == error)
			{
                MMS_IL_PRINT("0\n");

                return TIMM_OSAL_ERR_NONE;
            }
			else
			{
                MMS_IL_PRINT("Memory Dump failed!\n");

                return error;
            }//if (TIMM_OSAL_ERR_NONE == error)

        }//if (pComp->pMemMarshalling[i].pA9 == marshalCtx->nPtr)
    }//for (int i = 0; i < pComp->nMemMarshallingListSz; i++)

    MMS_IL_PRINT("Component has no associated allocated memory with address %p!\n", marshalCtx->nPtr);
    return TIMM_OSAL_ERR_UNKNOWN;
}