sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* This maps Symbian OS memory management onto Icu Umemory functions
|
sl@0
|
16 |
* Memory is allocated from the shaper internal heap, which has been saved in the TLS.
|
sl@0
|
17 |
* If there is no memory available these memory functions leave, this is caught in the shaper wrapper.
|
sl@0
|
18 |
* For debugging there is an alternative set of functions which log memory allocations
|
sl@0
|
19 |
*
|
sl@0
|
20 |
*/
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "unicode/uobject.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
#include <e32debug.h>
|
sl@0
|
26 |
|
sl@0
|
27 |
U_NAMESPACE_BEGIN
|
sl@0
|
28 |
|
sl@0
|
29 |
#if !defined SHAPER_MEMORY_DEBUG
|
sl@0
|
30 |
/* this is the production code versions */
|
sl@0
|
31 |
|
sl@0
|
32 |
void* UMemory::operator new(size_t size)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
return User::Alloc(size);
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
void UMemory::operator delete(void* p)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
return User::Free(p);
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
void* UMemory::operator new[](size_t size)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
return User::Alloc(size);
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
void UMemory::operator delete[](void* p)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
return User::Free(p);
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
|
sl@0
|
53 |
#else
|
sl@0
|
54 |
/* test versions for debugging shaper heap memory problems */
|
sl@0
|
55 |
|
sl@0
|
56 |
// just for testing record some details on the memory use
|
sl@0
|
57 |
TUint maxMemoryUsed = 0;
|
sl@0
|
58 |
|
sl@0
|
59 |
void* UMemory::operator new(size_t size)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
// For debugging trap OOM
|
sl@0
|
62 |
|
sl@0
|
63 |
// get a pointer to the heap in use from thread local storage
|
sl@0
|
64 |
void* pointer = User::Alloc(size);
|
sl@0
|
65 |
|
sl@0
|
66 |
// for development keep a count of the max heap used
|
sl@0
|
67 |
TInt totalAllocSize = 0;
|
sl@0
|
68 |
TInt used = User::AllocSize(totalAllocSize);
|
sl@0
|
69 |
if (totalAllocSize > maxMemoryUsed)
|
sl@0
|
70 |
maxMemoryUsed = totalAllocSize;
|
sl@0
|
71 |
|
sl@0
|
72 |
RDebug::Print(_L("UMemory::new %x size %d total heap %d cells %d "), pointer, size, totalAllocSize, used );
|
sl@0
|
73 |
|
sl@0
|
74 |
return pointer;
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
void UMemory::operator delete(void* p)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
RDebug::Print(_L("delete %x "), p );
|
sl@0
|
80 |
User::Free(p);
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
void* UMemory::operator new[](size_t size)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
// for development keep a count of the max heap used
|
sl@0
|
86 |
TInt totalAllocSize = 0;
|
sl@0
|
87 |
TInt used = User::AllocSize(totalAllocSize);
|
sl@0
|
88 |
if (totalAllocSize > maxMemoryUsed)
|
sl@0
|
89 |
maxMemoryUsed = totalAllocSize;
|
sl@0
|
90 |
|
sl@0
|
91 |
RDebug::Print(_L("new[] %x size %d total heap %d cells %d"), pointer, size, totalAllocSize, used);
|
sl@0
|
92 |
|
sl@0
|
93 |
return pointer;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
void UMemory::operator delete[](void* p)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
RDebug::Print(_L("delete[] %x "), p );
|
sl@0
|
99 |
User::Free(p);
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
void * UMemory::NewArray(int size, int count)
|
sl@0
|
103 |
{
|
sl@0
|
104 |
void* pointer = User::Alloc(size*count);
|
sl@0
|
105 |
RDebug::Print(_L("UMemory::NewArray %d bytes %x"), size * count, pointer );
|
sl@0
|
106 |
return pointer;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
/*
|
sl@0
|
110 |
For debugging code replacement for
|
sl@0
|
111 |
#define LE_GROW_ARRAY(array, newSize) ( ((RHeap*)Dll::Tls())->ReAllocL(array, (newSize) * sizeof (array)[0]))
|
sl@0
|
112 |
*/
|
sl@0
|
113 |
void * UMemory::GrowArray(void * array, int newSize )
|
sl@0
|
114 |
{
|
sl@0
|
115 |
void* pointer = User::ReAlloc(array, newSize);
|
sl@0
|
116 |
RDebug::Print(_L("UMemory::GrowArray %d new %d bytes %x"), array, newSize, pointer);
|
sl@0
|
117 |
return pointer;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
|
sl@0
|
121 |
void UMemory::FreeArray( void * array )
|
sl@0
|
122 |
{
|
sl@0
|
123 |
RDebug::Print(_L("delete array %x "), array);
|
sl@0
|
124 |
User::Free((void *)array);
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
/* end of debug versions */
|
sl@0
|
128 |
#endif
|
sl@0
|
129 |
|
sl@0
|
130 |
UObject::~UObject() {}
|
sl@0
|
131 |
|
sl@0
|
132 |
|
sl@0
|
133 |
|
sl@0
|
134 |
U_NAMESPACE_END
|