Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * This maps Symbian OS memory management onto Icu Umemory functions
16 * Memory is allocated from the shaper internal heap, which has been saved in the TLS.
17 * If there is no memory available these memory functions leave, this is caught in the shaper wrapper.
18 * For debugging there is an alternative set of functions which log memory allocations
23 #include "unicode/uobject.h"
29 #if !defined SHAPER_MEMORY_DEBUG
30 /* this is the production code versions */
32 void* UMemory::operator new(size_t size)
34 return User::Alloc(size);
37 void UMemory::operator delete(void* p)
42 void* UMemory::operator new[](size_t size)
44 return User::Alloc(size);
47 void UMemory::operator delete[](void* p)
54 /* test versions for debugging shaper heap memory problems */
56 // just for testing record some details on the memory use
57 TUint maxMemoryUsed = 0;
59 void* UMemory::operator new(size_t size)
61 // For debugging trap OOM
63 // get a pointer to the heap in use from thread local storage
64 void* pointer = User::Alloc(size);
66 // for development keep a count of the max heap used
67 TInt totalAllocSize = 0;
68 TInt used = User::AllocSize(totalAllocSize);
69 if (totalAllocSize > maxMemoryUsed)
70 maxMemoryUsed = totalAllocSize;
72 RDebug::Print(_L("UMemory::new %x size %d total heap %d cells %d "), pointer, size, totalAllocSize, used );
77 void UMemory::operator delete(void* p)
79 RDebug::Print(_L("delete %x "), p );
83 void* UMemory::operator new[](size_t size)
85 // for development keep a count of the max heap used
86 TInt totalAllocSize = 0;
87 TInt used = User::AllocSize(totalAllocSize);
88 if (totalAllocSize > maxMemoryUsed)
89 maxMemoryUsed = totalAllocSize;
91 RDebug::Print(_L("new[] %x size %d total heap %d cells %d"), pointer, size, totalAllocSize, used);
96 void UMemory::operator delete[](void* p)
98 RDebug::Print(_L("delete[] %x "), p );
102 void * UMemory::NewArray(int size, int count)
104 void* pointer = User::Alloc(size*count);
105 RDebug::Print(_L("UMemory::NewArray %d bytes %x"), size * count, pointer );
110 For debugging code replacement for
111 #define LE_GROW_ARRAY(array, newSize) ( ((RHeap*)Dll::Tls())->ReAllocL(array, (newSize) * sizeof (array)[0]))
113 void * UMemory::GrowArray(void * array, int newSize )
115 void* pointer = User::ReAlloc(array, newSize);
116 RDebug::Print(_L("UMemory::GrowArray %d new %d bytes %x"), array, newSize, pointer);
121 void UMemory::FreeArray( void * array )
123 RDebug::Print(_L("delete array %x "), array);
124 User::Free((void *)array);
127 /* end of debug versions */
130 UObject::~UObject() {}