1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/textshaperplugin/source/Umemory.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,134 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* This maps Symbian OS memory management onto Icu Umemory functions
1.19 +* Memory is allocated from the shaper internal heap, which has been saved in the TLS.
1.20 +* If there is no memory available these memory functions leave, this is caught in the shaper wrapper.
1.21 +* For debugging there is an alternative set of functions which log memory allocations
1.22 +*
1.23 +*/
1.24 +
1.25 +
1.26 +#include "unicode/uobject.h"
1.27 +
1.28 +#include <e32debug.h>
1.29 +
1.30 +U_NAMESPACE_BEGIN
1.31 +
1.32 +#if !defined SHAPER_MEMORY_DEBUG
1.33 +/* this is the production code versions */
1.34 +
1.35 +void* UMemory::operator new(size_t size)
1.36 + {
1.37 + return User::Alloc(size);
1.38 + }
1.39 +
1.40 +void UMemory::operator delete(void* p)
1.41 + {
1.42 + return User::Free(p);
1.43 + }
1.44 +
1.45 +void* UMemory::operator new[](size_t size)
1.46 + {
1.47 + return User::Alloc(size);
1.48 + }
1.49 +
1.50 +void UMemory::operator delete[](void* p)
1.51 + {
1.52 + return User::Free(p);
1.53 + }
1.54 +
1.55 +
1.56 +#else
1.57 +/* test versions for debugging shaper heap memory problems */
1.58 +
1.59 +// just for testing record some details on the memory use
1.60 +TUint maxMemoryUsed = 0;
1.61 +
1.62 +void* UMemory::operator new(size_t size)
1.63 + {
1.64 + // For debugging trap OOM
1.65 +
1.66 + // get a pointer to the heap in use from thread local storage
1.67 + void* pointer = User::Alloc(size);
1.68 +
1.69 + // for development keep a count of the max heap used
1.70 + TInt totalAllocSize = 0;
1.71 + TInt used = User::AllocSize(totalAllocSize);
1.72 + if (totalAllocSize > maxMemoryUsed)
1.73 + maxMemoryUsed = totalAllocSize;
1.74 +
1.75 + RDebug::Print(_L("UMemory::new %x size %d total heap %d cells %d "), pointer, size, totalAllocSize, used );
1.76 +
1.77 + return pointer;
1.78 + }
1.79 +
1.80 +void UMemory::operator delete(void* p)
1.81 + {
1.82 + RDebug::Print(_L("delete %x "), p );
1.83 + User::Free(p);
1.84 + }
1.85 +
1.86 +void* UMemory::operator new[](size_t size)
1.87 + {
1.88 + // for development keep a count of the max heap used
1.89 + TInt totalAllocSize = 0;
1.90 + TInt used = User::AllocSize(totalAllocSize);
1.91 + if (totalAllocSize > maxMemoryUsed)
1.92 + maxMemoryUsed = totalAllocSize;
1.93 +
1.94 + RDebug::Print(_L("new[] %x size %d total heap %d cells %d"), pointer, size, totalAllocSize, used);
1.95 +
1.96 + return pointer;
1.97 + }
1.98 +
1.99 +void UMemory::operator delete[](void* p)
1.100 + {
1.101 + RDebug::Print(_L("delete[] %x "), p );
1.102 + User::Free(p);
1.103 + }
1.104 +
1.105 +void * UMemory::NewArray(int size, int count)
1.106 + {
1.107 + void* pointer = User::Alloc(size*count);
1.108 + RDebug::Print(_L("UMemory::NewArray %d bytes %x"), size * count, pointer );
1.109 + return pointer;
1.110 + }
1.111 +
1.112 +/*
1.113 +For debugging code replacement for
1.114 +#define LE_GROW_ARRAY(array, newSize) ( ((RHeap*)Dll::Tls())->ReAllocL(array, (newSize) * sizeof (array)[0]))
1.115 +*/
1.116 +void * UMemory::GrowArray(void * array, int newSize )
1.117 + {
1.118 + void* pointer = User::ReAlloc(array, newSize);
1.119 + RDebug::Print(_L("UMemory::GrowArray %d new %d bytes %x"), array, newSize, pointer);
1.120 + return pointer;
1.121 + }
1.122 +
1.123 +
1.124 +void UMemory::FreeArray( void * array )
1.125 + {
1.126 + RDebug::Print(_L("delete array %x "), array);
1.127 + User::Free((void *)array);
1.128 + }
1.129 +
1.130 +/* end of debug versions */
1.131 +#endif
1.132 +
1.133 +UObject::~UObject() {}
1.134 +
1.135 +
1.136 +
1.137 +U_NAMESPACE_END