sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * This maps Symbian OS memory management onto Icu Umemory functions sl@0: * Memory is allocated from the shaper internal heap, which has been saved in the TLS. sl@0: * If there is no memory available these memory functions leave, this is caught in the shaper wrapper. sl@0: * For debugging there is an alternative set of functions which log memory allocations sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "unicode/uobject.h" sl@0: sl@0: #include sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: #if !defined SHAPER_MEMORY_DEBUG sl@0: /* this is the production code versions */ sl@0: sl@0: void* UMemory::operator new(size_t size) sl@0: { sl@0: return User::Alloc(size); sl@0: } sl@0: sl@0: void UMemory::operator delete(void* p) sl@0: { sl@0: return User::Free(p); sl@0: } sl@0: sl@0: void* UMemory::operator new[](size_t size) sl@0: { sl@0: return User::Alloc(size); sl@0: } sl@0: sl@0: void UMemory::operator delete[](void* p) sl@0: { sl@0: return User::Free(p); sl@0: } sl@0: sl@0: sl@0: #else sl@0: /* test versions for debugging shaper heap memory problems */ sl@0: sl@0: // just for testing record some details on the memory use sl@0: TUint maxMemoryUsed = 0; sl@0: sl@0: void* UMemory::operator new(size_t size) sl@0: { sl@0: // For debugging trap OOM sl@0: sl@0: // get a pointer to the heap in use from thread local storage sl@0: void* pointer = User::Alloc(size); sl@0: sl@0: // for development keep a count of the max heap used sl@0: TInt totalAllocSize = 0; sl@0: TInt used = User::AllocSize(totalAllocSize); sl@0: if (totalAllocSize > maxMemoryUsed) sl@0: maxMemoryUsed = totalAllocSize; sl@0: sl@0: RDebug::Print(_L("UMemory::new %x size %d total heap %d cells %d "), pointer, size, totalAllocSize, used ); sl@0: sl@0: return pointer; sl@0: } sl@0: sl@0: void UMemory::operator delete(void* p) sl@0: { sl@0: RDebug::Print(_L("delete %x "), p ); sl@0: User::Free(p); sl@0: } sl@0: sl@0: void* UMemory::operator new[](size_t size) sl@0: { sl@0: // for development keep a count of the max heap used sl@0: TInt totalAllocSize = 0; sl@0: TInt used = User::AllocSize(totalAllocSize); sl@0: if (totalAllocSize > maxMemoryUsed) sl@0: maxMemoryUsed = totalAllocSize; sl@0: sl@0: RDebug::Print(_L("new[] %x size %d total heap %d cells %d"), pointer, size, totalAllocSize, used); sl@0: sl@0: return pointer; sl@0: } sl@0: sl@0: void UMemory::operator delete[](void* p) sl@0: { sl@0: RDebug::Print(_L("delete[] %x "), p ); sl@0: User::Free(p); sl@0: } sl@0: sl@0: void * UMemory::NewArray(int size, int count) sl@0: { sl@0: void* pointer = User::Alloc(size*count); sl@0: RDebug::Print(_L("UMemory::NewArray %d bytes %x"), size * count, pointer ); sl@0: return pointer; sl@0: } sl@0: sl@0: /* sl@0: For debugging code replacement for sl@0: #define LE_GROW_ARRAY(array, newSize) ( ((RHeap*)Dll::Tls())->ReAllocL(array, (newSize) * sizeof (array)[0])) sl@0: */ sl@0: void * UMemory::GrowArray(void * array, int newSize ) sl@0: { sl@0: void* pointer = User::ReAlloc(array, newSize); sl@0: RDebug::Print(_L("UMemory::GrowArray %d new %d bytes %x"), array, newSize, pointer); sl@0: return pointer; sl@0: } sl@0: sl@0: sl@0: void UMemory::FreeArray( void * array ) sl@0: { sl@0: RDebug::Print(_L("delete array %x "), array); sl@0: User::Free((void *)array); sl@0: } sl@0: sl@0: /* end of debug versions */ sl@0: #endif sl@0: sl@0: UObject::~UObject() {} sl@0: sl@0: sl@0: sl@0: U_NAMESPACE_END