|
1 /* |
|
2 * Copyright (c) 2006 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 the License "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 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "FastAllocator.h" |
|
20 #include "MemoryManager.h" |
|
21 #include "MemoryPool.h" |
|
22 #include <e32std.h> |
|
23 #include <e32debug.h> |
|
24 |
|
25 RSymbianDlAllocatorWrapper::RSymbianDlAllocatorWrapper(CNewSymbianHeapPool* aPool) : iPool( aPool ) |
|
26 { |
|
27 #ifdef TRACK_ALLOCATIONS |
|
28 iNextCellId = 0; |
|
29 #endif |
|
30 } |
|
31 |
|
32 RSymbianDlAllocatorWrapper::~RSymbianDlAllocatorWrapper() |
|
33 { |
|
34 } |
|
35 |
|
36 TAny* RSymbianDlAllocatorWrapper::Alloc(TInt aSize) |
|
37 { |
|
38 #ifdef TRACK_ALLOCATIONS |
|
39 return TraceAlloc(iPool, &aSize, &iNextCellId); |
|
40 #else |
|
41 return iPool->Allocate( aSize ); |
|
42 #endif |
|
43 } |
|
44 |
|
45 void RSymbianDlAllocatorWrapper::Free(TAny* aPtr) |
|
46 { |
|
47 #ifdef TRACK_ALLOCATIONS |
|
48 TraceFree(&aPtr); |
|
49 #endif |
|
50 iPool->Free( aPtr ); |
|
51 } |
|
52 |
|
53 TAny* RSymbianDlAllocatorWrapper::ReAlloc(TAny* aPtr, TInt aSize, TInt aMode) |
|
54 { |
|
55 #ifdef TRACK_ALLOCATIONS |
|
56 TUint32 originalCellId; |
|
57 TBool issueNewCellId = TracePreRealloc(&aPtr, &aSize, originalCellId); |
|
58 #endif |
|
59 |
|
60 TAny* p = iPool->ReAllocate( aPtr, aSize ); |
|
61 |
|
62 // Handle aMode. |
|
63 // 0: default. Don't move on shrink, but can move if growing |
|
64 // ENeverMove: Don't move memory on realloc, return NULL if it was moved. |
|
65 // EAllowMoveOnShrink: Allow moving memory on realloc when size requested |
|
66 // is smaller, return NULL if moved and request size is greater (equal). |
|
67 // |
|
68 // This allocator only operates in mode 0 (for now), so we only have to check the stricter ENeverMove mode |
|
69 // |
|
70 if ( (aMode == ENeverMove && p != aPtr) ) |
|
71 { |
|
72 Free(p); |
|
73 return NULL; |
|
74 } |
|
75 #ifdef TRACK_ALLOCATIONS |
|
76 TracePostRealloc(&p, aSize, &iNextCellId, originalCellId, issueNewCellId); |
|
77 #endif |
|
78 return p; |
|
79 } |
|
80 |
|
81 TInt RSymbianDlAllocatorWrapper::AllocLen(const TAny* aCell) const |
|
82 { |
|
83 #ifdef TRACK_ALLOCATIONS |
|
84 if(aCell) |
|
85 aCell = GetRealPtrFromClientPtr((TAny*)aCell); |
|
86 TInt size = iPool->MemorySize( (void*)(aCell) ); |
|
87 DecreaseSizeInPlace(size); |
|
88 return size; |
|
89 #else |
|
90 return iPool->MemorySize( (void*)(aCell) ); |
|
91 #endif |
|
92 } |
|
93 |
|
94 TInt RSymbianDlAllocatorWrapper::Compress() |
|
95 { |
|
96 // DO NOTHING |
|
97 return 0; |
|
98 } |
|
99 |
|
100 void RSymbianDlAllocatorWrapper::Reset() |
|
101 { |
|
102 // DO NOTHING |
|
103 } |
|
104 |
|
105 TInt RSymbianDlAllocatorWrapper::AllocSize(TInt& aTotalAllocSize) const |
|
106 { |
|
107 // allocated cell size |
|
108 aTotalAllocSize = 0; |
|
109 return 0; |
|
110 } |
|
111 |
|
112 TInt RSymbianDlAllocatorWrapper::Available(TInt& aBiggestBlock) const |
|
113 { |
|
114 // make sure the caller is not scared of futher allocation |
|
115 aBiggestBlock = KMaxTInt; |
|
116 return KMaxTUint; |
|
117 } |
|
118 |
|
119 TInt RSymbianDlAllocatorWrapper::DebugFunction(TInt, TAny*, TAny*) |
|
120 { |
|
121 return 0; |
|
122 } |
|
123 |
|
124 TInt RSymbianDlAllocatorWrapper::Extension_(TUint, TAny*&, TAny*) |
|
125 { |
|
126 return 0; |
|
127 } |
|
128 |
|
129 // END OF FILE |