commsfwutils/commsbufs/mbufmgrimpl/src/MBufMemoryManager.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Heap Memory Allocation for CMBufPoolManager 
       
    15 //
       
    16 //
       
    17 /**
       
    18  * @file
       
    19  *
       
    20  * Heap Memory Allocation for CMBufPoolManager 
       
    21  * 
       
    22  * @internalComponent
       
    23  */
       
    24 
       
    25 #include "mbufmanager.h"
       
    26 #include "MBufMemoryManager.h"
       
    27 #include "MBufPool.h"
       
    28 #include "MBuf_Log.h" // for __FLOG_*
       
    29 
       
    30 #ifdef __FLOG_ACTIVE
       
    31 _LIT8(KComponent, "MemoryManager");
       
    32 #endif
       
    33 
       
    34 CMBufMemoryManager* CMBufMemoryManager::NewL(TInt aMaxHeapSize)
       
    35 //
       
    36 // Construction - first phase
       
    37 //
       
    38 	{
       
    39 	CMBufMemoryManager* memAllocator = new(ELeave) CMBufMemoryManager;
       
    40 	CleanupStack::PushL(memAllocator);
       
    41 	memAllocator->ConstructL(aMaxHeapSize);
       
    42 	CleanupStack::Pop();
       
    43 	
       
    44 	return memAllocator;
       
    45 	}
       
    46 
       
    47 CMBufMemoryManager::CMBufMemoryManager()
       
    48 	: CBase()
       
    49 //
       
    50 // Constructor
       
    51 //
       
    52 	{
       
    53 	__FLOG_OPEN(KSubsysMBufMgr, KComponent);
       
    54 	__FLOG_1(_L8("CMBufManager %x:\tCMBufMemoryManager()"),this);
       
    55 
       
    56 	}
       
    57 
       
    58 void CMBufMemoryManager::ConstructL(TInt aMaxHeapSize)
       
    59 //
       
    60 // Construction - second phase
       
    61 //
       
    62 	{
       
    63 	iHeap = UserHeap::ChunkHeap(NULL, 0, aMaxHeapSize);
       
    64 	if (iHeap==NULL)
       
    65 		{
       
    66 		__FLOG_2(_L8("CMBufManager::CMBufMemoryManager %x:\tCreateL(0, aMaxHeapSize %d) leaving with KErrNoMemory"), this, aMaxHeapSize);
       
    67 		User::Leave(KErrNoMemory);
       
    68 		}
       
    69 	}
       
    70 
       
    71 CMBufMemoryManager::~CMBufMemoryManager()
       
    72 //
       
    73 // Destructor
       
    74 //
       
    75 	{
       
    76 	iHeap->Close();
       
    77 
       
    78 	__FLOG_CLOSE;
       
    79 	}
       
    80 
       
    81 TAny* CMBufMemoryManager::Alloc(TInt aSize)
       
    82 //
       
    83 // Allocates memory from the heap
       
    84 //
       
    85 	{
       
    86 	TAny* pMemory;
       
    87 	pMemory = iHeap->Alloc(aSize);
       
    88 
       
    89 	return pMemory;
       
    90 	}
       
    91 
       
    92 void CMBufMemoryManager::Free(TAny* aPtr)
       
    93 //
       
    94 // Returns memory to the heap
       
    95 //
       
    96 	{
       
    97 	CMBufPool* pool = (CMBufPool* ) aPtr;
       
    98 	
       
    99 	iHeap->Free(pool);
       
   100 	}
       
   101 
       
   102 TInt CMBufMemoryManager::AllocBytes()
       
   103 //
       
   104 // Number of bytes allocated from the heap
       
   105 //
       
   106 	{
       
   107 	TInt allocated;
       
   108 	iHeap->AllocSize(allocated);
       
   109 	
       
   110 	return allocated;
       
   111 	}
       
   112