os/textandloc/fontservices/textshaperplugin/source/Umemory.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    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
    19 *
    20 */
    21 
    22 
    23 #include "unicode/uobject.h"
    24 
    25 #include <e32debug.h>
    26 
    27 U_NAMESPACE_BEGIN
    28 
    29 #if !defined  SHAPER_MEMORY_DEBUG
    30 /* this is the production code versions */
    31 
    32 void* UMemory::operator new(size_t size)
    33 	{
    34 	return User::Alloc(size);
    35 	}
    36 
    37 void UMemory::operator delete(void* p)
    38 	{
    39 	return User::Free(p);
    40 	}
    41 
    42 void* UMemory::operator new[](size_t size)
    43 	{
    44 	return User::Alloc(size);
    45 	}
    46 
    47 void UMemory::operator delete[](void* p)
    48 	{
    49 	return User::Free(p);
    50 	}
    51 
    52 	
    53 #else 
    54 /* test versions for debugging shaper heap memory problems */
    55 
    56 // just for testing record some details on the memory use
    57 TUint maxMemoryUsed = 0;
    58 
    59 void* UMemory::operator new(size_t size)
    60 	{
    61 	// For debugging trap OOM
    62 		
    63 	// get a pointer to the heap in use from thread local storage	
    64 	void* pointer = User::Alloc(size);
    65 	
    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;
    71 
    72 	RDebug::Print(_L("UMemory::new %x size %d total heap %d cells %d "), pointer, size, totalAllocSize, used );
    73 	
    74 	return pointer;
    75 	}
    76 
    77 void UMemory::operator delete(void* p)
    78 	{
    79 	RDebug::Print(_L("delete %x "), p );
    80 	User::Free(p);
    81 	}
    82 
    83 void* UMemory::operator new[](size_t size)
    84 	{
    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;
    90 	
    91 	RDebug::Print(_L("new[] %x size %d total heap %d cells %d"), pointer, size, totalAllocSize, used);
    92 
    93 	return pointer;
    94 	}
    95 
    96 void UMemory::operator delete[](void* p)
    97 	{
    98 	RDebug::Print(_L("delete[] %x "), p );
    99 	User::Free(p);
   100 	}
   101 
   102 void * UMemory::NewArray(int size, int count) 
   103 	{
   104 	void* pointer = User::Alloc(size*count);
   105 	RDebug::Print(_L("UMemory::NewArray %d bytes %x"), size * count, pointer );
   106 	return pointer;
   107 	}
   108 
   109 /*
   110 For debugging code replacement for
   111 #define LE_GROW_ARRAY(array, newSize) ( ((RHeap*)Dll::Tls())->ReAllocL(array, (newSize) * sizeof (array)[0]))
   112 */
   113 void * UMemory::GrowArray(void * array, int newSize ) 
   114 	{
   115 	void* pointer = User::ReAlloc(array, newSize);
   116 	RDebug::Print(_L("UMemory::GrowArray %d new %d bytes %x"), array, newSize, pointer);
   117 	return pointer;
   118 	}
   119 
   120 
   121 void UMemory::FreeArray( void * array ) 
   122 	{
   123 	RDebug::Print(_L("delete array %x "), array);
   124 	User::Free((void *)array);
   125 	}
   126 
   127 /* end of debug versions */
   128 #endif
   129 
   130 UObject::~UObject() {}
   131 
   132 
   133 
   134 U_NAMESPACE_END