| 26 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 27 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 28 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 29 | | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 30 | | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 31 | | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 32 | | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 33 | | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 34 | | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 35 | | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 36 | | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 37 | | * DAMAGE. |
| | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| | 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| | 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| | 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| | 30 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| | 31 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| | 32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| | 33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| | 34 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| | 35 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| | 36 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| | 37 | * DAMAGE. |
| 77 | | { |
| 78 | | public: |
| 79 | | virtual ~CAllocator(); |
| 80 | | |
| 81 | | /** |
| 82 | | * create the allocator |
| 83 | | * @since 3.1 |
| 84 | | * @param aSize bytes of memory to be allocated |
| 85 | | * @return pointer to the allocated memory |
| 86 | | */ |
| 87 | | virtual TBool Create(); |
| 88 | | |
| 89 | | /** |
| 90 | | * allocate a memory buffer |
| 91 | | * @since 3.1 |
| 92 | | * @param aSize bytes of memory to be allocated |
| 93 | | * @return pointer to the allocated memory |
| 94 | | */ |
| 95 | | virtual TAny* Allocate( TUint aSize ) = 0; |
| 96 | | |
| 97 | | /** |
| 98 | | * realloc a memory buffer |
| 99 | | * @since 3.1 |
| 100 | | * @param aSize bytes of memory to be allocated |
| 101 | | * @return pointer to the allocated memory |
| 102 | | */ |
| 103 | | virtual TAny* ReAllocate( TAny* aPtr, TUint aSize ) = 0; |
| 104 | | |
| 105 | | /** |
| 106 | | * free the memory |
| 107 | | * @since 3.1 |
| 108 | | * @param aPtr pointer to the memory to be freed |
| 109 | | * @param |
| 110 | | * @return |
| 111 | | */ |
| 112 | | virtual void Free( TAny* aPtr ) = 0; |
| 113 | | |
| 114 | | /** |
| 115 | | * get the size of a memory buffer |
| 116 | | * @since 3.1 |
| 117 | | * @param aPtr pointer to the memory buffer |
| 118 | | * @param |
| 119 | | * @return size of memory buffer |
| 120 | | */ |
| 121 | | virtual TUint MemorySize( TAny* aPtr ) = 0; |
| 122 | | |
| 123 | | /** |
| 124 | | * register a memory collector, memory manager doesn't own this collector |
| 125 | | * @since 3.1 |
| 126 | | * @param aCollector the collector to be registered |
| 127 | | * @param |
| 128 | | * @return |
| 129 | | */ |
| 130 | | void AddCollector( MMemoryCollector* aCollector ); |
| 131 | | |
| 132 | | /** |
| 133 | | * unregister a memory collector |
| 134 | | * @since 3.1 |
| 135 | | * @param aCollector the collector to be unregistered |
| 136 | | * @param |
| 137 | | * @return |
| 138 | | */ |
| 139 | | void RemoveCollector( MMemoryCollector* aCollector ); |
| 140 | | |
| 141 | | /** |
| 142 | | * collect free memory from memory collectors |
| 143 | | * @since 3.1 |
| 144 | | * @param |
| 145 | | * @return |
| 146 | | */ |
| 147 | | void CollectMemory(TUint aSize=-1); |
| 148 | | |
| 149 | | /** |
| 150 | | * restore the states of memory collectors |
| 151 | | * @since 3.1 |
| 152 | | * @param |
| 153 | | * @return |
| 154 | | */ |
| 155 | | void RestoreCollectors( TOOMPriority aPriority ); |
| 156 | | |
| 157 | | /** |
| 158 | | * register a stopper, memory manager doesn't own this stopper. |
| 159 | | * @since 3.1 |
| 160 | | * @param aStopper the stopper to be registered |
| 161 | | * @param |
| 162 | | * @return |
| 163 | | */ |
| 164 | | void AddStopper( MOOMStopper* aStopper ); |
| 165 | | |
| 166 | | /** |
| 167 | | * unregister a stopper |
| 168 | | * @since 3.1 |
| 169 | | * @param aStopper the stopper to be unregistered |
| 170 | | * @param |
| 171 | | * @return |
| 172 | | */ |
| 173 | | void RemoveStopper( MOOMStopper* aStopper ); |
| 174 | | |
| 175 | | /** |
| 176 | | * toggle the stopping status of memory manager |
| 177 | | * @since 3.1 |
| 178 | | * @param aStopping |
| 179 | | * @param |
| 180 | | * @return |
| 181 | | */ |
| 182 | | void SetStopping( TBool aStopping ); |
| 183 | | |
| 184 | | /** |
| 185 | | * get the array of stoppers, used by stopscheduler |
| 186 | | * @since 3.1 |
| 187 | | * @param |
| 188 | | * @param |
| 189 | | * @return an array of stoppers |
| 190 | | */ |
| 191 | | RPointerArray<MOOMStopper>& Stoppers() { return iStoppers; } |
| 192 | | |
| 193 | | /** |
| 194 | | * set the OOM notifier, memory manager doesn't own this notifier |
| 195 | | * @since 3.1 |
| 196 | | * @param aNotifier the notifier |
| 197 | | * @param |
| 198 | | * @return |
| 199 | | */ |
| 200 | | void SetNotifier( MOOMNotifier* aNotifier ); |
| 201 | | |
| 202 | | /** |
| 203 | | * check if the memory manager is able to reserve enough memory for the coming operation. |
| 204 | | * @since 3.1 |
| 205 | | * @param aTotalSize total amount of memory |
| 206 | | * @param aMaxBufSizse the biggest contiguous memory buffer |
| 207 | | * @param aChecker the name of operation |
| 208 | | * @return result of prechecking, ETrue = successful |
| 209 | | */ |
| 210 | | TBool PreCheck( TUint aTotalSize, TUint aMaxBufSize, const TDesC8& aChecker ); |
| 211 | | |
| 212 | | /** |
| 213 | | * An additional check after an operation is completed. |
| 214 | | * @since 3.1 |
| 215 | | * @param |
| 216 | | * @param |
| 217 | | * @return the status of memory during this operation. |
| 218 | | */ |
| 219 | | TUint PostCheck(); |
| 220 | | |
| 221 | | /** |
| 222 | | * Trigger an OOM event, this function is only for debugging purpose |
| 223 | | * @since 3.1 |
| 224 | | * @param aType defines where memory allocation fails |
| 225 | | * @param |
| 226 | | * @return |
| 227 | | */ |
| 228 | | void TriggerOOM( TOOMType aType ); |
| 229 | | |
| 230 | | /** |
| 231 | | * get status of memory manager |
| 232 | | * @since 3.1 |
| 233 | | * @param |
| 234 | | * @param |
| 235 | | * @return the status |
| 236 | | */ |
| 237 | | TUint Status() { return iMemStatus; } |
| 238 | | |
| 239 | | void SetStatus( TOOMCheckResult aStatus ); |
| | 77 | { |
| | 78 | public: |
| | 79 | virtual ~CAllocator(); |
| | 80 | |
| | 81 | /** |
| | 82 | * create the allocator |
| | 83 | * @since 3.1 |
| | 84 | * @param aSize bytes of memory to be allocated |
| | 85 | * @return pointer to the allocated memory |
| | 86 | */ |
| | 87 | virtual TBool Create(); |
| | 88 | |
| | 89 | /** |
| | 90 | * allocate a memory buffer |
| | 91 | * @since 3.1 |
| | 92 | * @param aSize bytes of memory to be allocated |
| | 93 | * @return pointer to the allocated memory |
| | 94 | */ |
| | 95 | virtual TAny* Allocate( TUint aSize ) = 0; |
| | 96 | |
| | 97 | /** |
| | 98 | * realloc a memory buffer |
| | 99 | * @since 3.1 |
| | 100 | * @param aSize bytes of memory to be allocated |
| | 101 | * @return pointer to the allocated memory |
| | 102 | */ |
| | 103 | virtual TAny* ReAllocate( TAny* aPtr, TUint aSize ) = 0; |
| | 104 | |
| | 105 | /** |
| | 106 | * free the memory |
| | 107 | * @since 3.1 |
| | 108 | * @param aPtr pointer to the memory to be freed |
| | 109 | * @param |
| | 110 | * @return |
| | 111 | */ |
| | 112 | virtual void Free( TAny* aPtr ) = 0; |
| | 113 | |
| | 114 | /** |
| | 115 | * get the size of a memory buffer |
| | 116 | * @since 3.1 |
| | 117 | * @param aPtr pointer to the memory buffer |
| | 118 | * @param |
| | 119 | * @return size of memory buffer |
| | 120 | */ |
| | 121 | virtual TUint MemorySize( TAny* aPtr ) = 0; |
| | 122 | |
| | 123 | /** |
| | 124 | * register a memory collector, memory manager doesn't own this collector |
| | 125 | * @since 3.1 |
| | 126 | * @param aCollector the collector to be registered |
| | 127 | * @param |
| | 128 | * @return |
| | 129 | */ |
| | 130 | void AddCollector( MMemoryCollector* aCollector ); |
| | 131 | |
| | 132 | /** |
| | 133 | * unregister a memory collector |
| | 134 | * @since 3.1 |
| | 135 | * @param aCollector the collector to be unregistered |
| | 136 | * @param |
| | 137 | * @return |
| | 138 | */ |
| | 139 | void RemoveCollector( MMemoryCollector* aCollector ); |
| | 140 | |
| | 141 | /** |
| | 142 | * collect free memory from memory collectors |
| | 143 | * @since 3.1 |
| | 144 | * @param |
| | 145 | * @return |
| | 146 | */ |
| | 147 | void CollectMemory(TUint aSize=-1); |
| | 148 | |
| | 149 | /** |
| | 150 | * restore the states of memory collectors |
| | 151 | * @since 3.1 |
| | 152 | * @param |
| | 153 | * @return |
| | 154 | */ |
| | 155 | void RestoreCollectors( TOOMPriority aPriority ); |
| | 156 | |
| | 157 | /** |
| | 158 | * register a stopper, memory manager doesn't own this stopper. |
| | 159 | * @since 3.1 |
| | 160 | * @param aStopper the stopper to be registered |
| | 161 | * @param |
| | 162 | * @return |
| | 163 | */ |
| | 164 | void AddStopper( MOOMStopper* aStopper ); |
| | 165 | |
| | 166 | /** |
| | 167 | * unregister a stopper |
| | 168 | * @since 3.1 |
| | 169 | * @param aStopper the stopper to be unregistered |
| | 170 | * @param |
| | 171 | * @return |
| | 172 | */ |
| | 173 | void RemoveStopper( MOOMStopper* aStopper ); |
| | 174 | |
| | 175 | /** |
| | 176 | * toggle the stopping status of memory manager |
| | 177 | * @since 3.1 |
| | 178 | * @param aStopping |
| | 179 | * @param |
| | 180 | * @return |
| | 181 | */ |
| | 182 | void SetStopping( TBool aStopping ); |
| | 183 | |
| | 184 | /** |
| | 185 | * get the array of stoppers, used by stopscheduler |
| | 186 | * @since 3.1 |
| | 187 | * @param |
| | 188 | * @param |
| | 189 | * @return an array of stoppers |
| | 190 | */ |
| | 191 | RPointerArray<MOOMStopper>& Stoppers() { return iStoppers; } |
| | 192 | |
| | 193 | /** |
| | 194 | * set the OOM notifier, memory manager doesn't own this notifier |
| | 195 | * @since 3.1 |
| | 196 | * @param aNotifier the notifier |
| | 197 | * @param |
| | 198 | * @return |
| | 199 | */ |
| | 200 | void SetNotifier( MOOMNotifier* aNotifier ); |
| | 201 | |
| | 202 | /** |
| | 203 | * check if the memory manager is able to reserve enough memory for the coming operation. |
| | 204 | * @since 3.1 |
| | 205 | * @param aTotalSize total amount of memory |
| | 206 | * @param aMaxBufSizse the biggest contiguous memory buffer |
| | 207 | * @param aChecker the name of operation |
| | 208 | * @return result of prechecking, ETrue = successful |
| | 209 | */ |
| | 210 | TBool PreCheck( TUint aTotalSize, TUint aMaxBufSize, const TDesC8& aChecker ); |
| | 211 | |
| | 212 | /** |
| | 213 | * An additional check after an operation is completed. |
| | 214 | * @since 3.1 |
| | 215 | * @param |
| | 216 | * @param |
| | 217 | * @return the status of memory during this operation. |
| | 218 | */ |
| | 219 | TUint PostCheck(); |
| | 220 | |
| | 221 | /** |
| | 222 | * Trigger an OOM event, this function is only for debugging purpose |
| | 223 | * @since 3.1 |
| | 224 | * @param aType defines where memory allocation fails |
| | 225 | * @param |
| | 226 | * @return |
| | 227 | */ |
| | 228 | void TriggerOOM( TOOMType aType ); |
| | 229 | |
| | 230 | /** |
| | 231 | * get status of memory manager |
| | 232 | * @since 3.1 |
| | 233 | * @param |
| | 234 | * @param |
| | 235 | * @return the status |
| | 236 | */ |
| | 237 | TUint Status() { return iMemStatus; } |
| | 238 | |
| | 239 | void SetStatus( TOOMCheckResult aStatus ); |