commsfwutils/commsbufs/version1/mbufmgr/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 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <es_mbman.h>
       
    24 #include "MBufMemoryManager.h"
       
    25 #include "MBufPool.h"
       
    26 #include "MBuf_Log.h" // for __FLOG_*
       
    27 
       
    28 #ifdef __FLOG_ACTIVE
       
    29 _LIT8(KComponent, "MemoryManager");
       
    30 #endif
       
    31 
       
    32 CMBufMemoryManager* CMBufMemoryManager::NewL(TInt aMaxHeapSize)
       
    33 //
       
    34 // Construction - first phase
       
    35 //
       
    36 	{
       
    37 	CMBufMemoryManager* memAllocator = new(ELeave) CMBufMemoryManager;
       
    38 	CleanupStack::PushL(memAllocator);
       
    39 	memAllocator->ConstructL(aMaxHeapSize);
       
    40 	CleanupStack::Pop();
       
    41 	
       
    42 	return memAllocator;
       
    43 	}
       
    44 
       
    45 CMBufMemoryManager::CMBufMemoryManager()
       
    46 	: CBase()
       
    47 //
       
    48 // Constructor
       
    49 //
       
    50 	{
       
    51 	__FLOG_OPEN(KSubsysMBufMgr, KComponent);
       
    52 	__FLOG_1(_L8("CMBufManager %x:\tCMBufMemoryManager()"),this);
       
    53 
       
    54 	}
       
    55 
       
    56 void CMBufMemoryManager::ConstructL(TInt aMaxHeapSize)
       
    57 //
       
    58 // Construction - second phase
       
    59 //
       
    60 	{
       
    61 	iHeap = UserHeap::ChunkHeap(NULL, 0, aMaxHeapSize);
       
    62 	if (iHeap==NULL)
       
    63 		{
       
    64 		__FLOG_2(_L8("CMBufManager::CMBufMemoryManager %x:\tCreateL(0, aMaxHeapSize %d) leaving with KErrNoMemory"), this, aMaxHeapSize);
       
    65 		User::Leave(KErrNoMemory);
       
    66 		}
       
    67 	}
       
    68 
       
    69 CMBufMemoryManager::~CMBufMemoryManager()
       
    70 //
       
    71 // Destructor
       
    72 //
       
    73 	{
       
    74 	iHeap->Close();
       
    75 
       
    76 	__FLOG_CLOSE;
       
    77 	}
       
    78 
       
    79 TAny* CMBufMemoryManager::Alloc(TInt aSize)
       
    80 //
       
    81 // Allocates memory from the heap
       
    82 //
       
    83 	{
       
    84 	TAny* pMemory;
       
    85 	pMemory = iHeap->Alloc(aSize);
       
    86 
       
    87 	return pMemory;
       
    88 	}
       
    89 
       
    90 void CMBufMemoryManager::Free(TAny* aPtr)
       
    91 //
       
    92 // Returns memory to the heap
       
    93 //
       
    94 	{
       
    95 	CMBufPool* pool = (CMBufPool* ) aPtr;
       
    96 	
       
    97 	iHeap->Free(pool);
       
    98 	}
       
    99 
       
   100 TInt CMBufMemoryManager::AllocBytes()
       
   101 //
       
   102 // Number of bytes allocated from the heap
       
   103 //
       
   104 	{
       
   105 	TInt allocated;
       
   106 	iHeap->AllocSize(allocated);
       
   107 	
       
   108 	return allocated;
       
   109 	}
       
   110