|
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 FILES |
|
20 |
|
21 #include "MemoryManager.h" |
|
22 #include "MemoryPool.h" |
|
23 #include "FastAllocator.h" |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 _LIT( KMemManPanicDes, "MemMan:0" ); |
|
28 |
|
29 // CLASS DECLARATION |
|
30 |
|
31 // initializing a global memory pool. |
|
32 static CMemoryPool *s_pool = 0; |
|
33 |
|
34 //----------------------------------------------------------------------------- |
|
35 // Pool() - a utility function for accessing the right memory pool |
|
36 //----------------------------------------------------------------------------- |
|
37 inline CMemoryPool* Pool() |
|
38 { |
|
39 if( !s_pool ) { |
|
40 // applications using fast memory pool already created the pool at |
|
41 // startup. |
|
42 s_pool = new CDefaultMemoryPool(); |
|
43 s_pool->Create(); |
|
44 } |
|
45 |
|
46 return s_pool; |
|
47 } |
|
48 |
|
49 //----------------------------------------------------------------------------- |
|
50 // MemoryManager::SwitchToFastAllocator |
|
51 //----------------------------------------------------------------------------- |
|
52 EXPORT_C RAllocator* MemoryManager::SwitchToFastAllocator() |
|
53 { |
|
54 // create the right memory pool |
|
55 __ASSERT_DEBUG( s_pool == 0, User::Panic( KMemManPanicDes, 0 ) ); |
|
56 s_pool = new CFastMemoryPool(); |
|
57 s_pool->Create(); |
|
58 RFastAllocator* allocator = new RFastAllocator((CFastMemoryPool*)s_pool); |
|
59 return User::SwitchAllocator( allocator ); |
|
60 } |
|
61 |
|
62 //----------------------------------------------------------------------------- |
|
63 // MemoryManager::CloseFastAllocator |
|
64 //----------------------------------------------------------------------------- |
|
65 EXPORT_C void MemoryManager::CloseFastAllocator(RAllocator* aDefaultAllocator) |
|
66 { |
|
67 RAllocator* allocator = User::SwitchAllocator( aDefaultAllocator ); |
|
68 delete (RFastAllocator*)(allocator); |
|
69 } |
|
70 |
|
71 //----------------------------------------------------------------------------- |
|
72 // MemoryManager::AddCollector |
|
73 //----------------------------------------------------------------------------- |
|
74 EXPORT_C void MemoryManager::AddCollector( MMemoryCollector* aCollector ) |
|
75 { |
|
76 Pool()->AddCollector( aCollector ); |
|
77 } |
|
78 |
|
79 //----------------------------------------------------------------------------- |
|
80 // MemoryManager::RemoveCollector |
|
81 //----------------------------------------------------------------------------- |
|
82 EXPORT_C void MemoryManager::RemoveCollector( MMemoryCollector* aCollector ) |
|
83 { |
|
84 Pool()->RemoveCollector( aCollector ); |
|
85 } |
|
86 |
|
87 //----------------------------------------------------------------------------- |
|
88 // MemoryManager::AddStopper |
|
89 //----------------------------------------------------------------------------- |
|
90 EXPORT_C void MemoryManager::AddStopper( MOOMStopper* aStopper ) |
|
91 { |
|
92 Pool()->AddStopper( aStopper ); |
|
93 } |
|
94 |
|
95 //----------------------------------------------------------------------------- |
|
96 // MemoryManager::RemoveStopper |
|
97 //----------------------------------------------------------------------------- |
|
98 EXPORT_C void MemoryManager::RemoveStopper( MOOMStopper* aStopper ) |
|
99 { |
|
100 Pool()->RemoveStopper( aStopper ); |
|
101 } |
|
102 |
|
103 //----------------------------------------------------------------------------- |
|
104 // MemoryManager::SetNotifier |
|
105 //----------------------------------------------------------------------------- |
|
106 EXPORT_C void MemoryManager::SetNotifier( MOOMNotifier* aNotifier ) |
|
107 { |
|
108 Pool()->SetNotifier( aNotifier ); |
|
109 } |
|
110 |
|
111 //----------------------------------------------------------------------------- |
|
112 // MemoryManager::PreCheck |
|
113 //----------------------------------------------------------------------------- |
|
114 EXPORT_C TBool MemoryManager::PreCheck( TUint aTotalSize, TUint aMaxBufSize, const TDesC8& aChecker ) |
|
115 { |
|
116 return Pool()->PreCheck( aTotalSize, aMaxBufSize, aChecker ); |
|
117 } |
|
118 |
|
119 //----------------------------------------------------------------------------- |
|
120 // MemoryManager::PostCheck |
|
121 //----------------------------------------------------------------------------- |
|
122 EXPORT_C TUint MemoryManager::PostCheck() |
|
123 { |
|
124 return Pool()->PostCheck(); |
|
125 } |
|
126 |
|
127 //----------------------------------------------------------------------------- |
|
128 // MemoryManager::SetStatus |
|
129 //----------------------------------------------------------------------------- |
|
130 EXPORT_C void MemoryManager::SetStatus( TOOMCheckResult aType ) |
|
131 { |
|
132 Pool()->SetStatus( aType ); |
|
133 } |
|
134 |
|
135 //----------------------------------------------------------------------------- |
|
136 // MemoryManager::Status |
|
137 //----------------------------------------------------------------------------- |
|
138 EXPORT_C TUint MemoryManager::Status() |
|
139 { |
|
140 return Pool()->Status(); |
|
141 } |
|
142 |
|
143 //----------------------------------------------------------------------------- |
|
144 // MemoryManager::FreeRam |
|
145 //----------------------------------------------------------------------------- |
|
146 EXPORT_C void MemoryManager::FreeRam() |
|
147 { |
|
148 Pool()->CollectMemory(); |
|
149 } |
|
150 |
|
151 //----------------------------------------------------------------------------- |
|
152 // MemoryManager::RestoreCollectors |
|
153 //----------------------------------------------------------------------------- |
|
154 EXPORT_C void MemoryManager::RestoreCollectors() |
|
155 { |
|
156 Pool()->RestoreCollectors(EOOM_PriorityLow); |
|
157 } |
|
158 |
|
159 //----------------------------------------------------------------------------- |
|
160 // MemoryManager::SetRescueBufferSize |
|
161 //----------------------------------------------------------------------------- |
|
162 EXPORT_C void MemoryManager::SetRescueBufferSize( TInt aSize ) |
|
163 { |
|
164 Pool()->SetRescueBufferSize( aSize ); |
|
165 } |
|
166 |
|
167 //----------------------------------------------------------------------------- |
|
168 // MemoryManager::MemorySize |
|
169 //----------------------------------------------------------------------------- |
|
170 EXPORT_C TUint MemoryManager::MemorySize( TAny* aPtr ) |
|
171 { |
|
172 return Pool()->MemorySize( aPtr ); |
|
173 } |
|
174 |