/* ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. This file is part of ChibiOS/RT. ChibiOS/RT is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ChibiOS/RT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /** * @page article_manage_memory How to manage memory * ChibiOS/RT is a static kernel so you don't need to manage memory at all * if your application doesn't really require it. This doesn't mean that * the OS is unable to manage memory but just that memory management is an * optional part of the whole.
* The OS offers three distinct ways to manage memory, each one with its * weaknesses and strengths: * - Core Memory Manager. See @ref memcore. * - Heap Allocator. See @ref heaps. * - Memory Pools. See @ref pools. * . * The three mechanisms are able to coexist and are well integrated, as example * the heap allocator uses the core memory manager in order to get more * memory blocks, memory pools can optionally do the same thing. * *

The three subsystems

* This is a small comparison table regarding the three subsystems, C-runtime * and static objects are thrown there for comparison:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Subsystem * * Free capable * * Constant time * * Safe * * From IRQ * * Notes *
* Static Objects * N/AN/AYESYES * Preferred solution for safety applications. *
* Core Memory Manager * NOYESYESYES * Fast and safe but unable to free allocated memory. *
* Heap Allocator * YESNONONO * Unsafe because fragmentation and not constant time, cannot be used * from IRQ handlers. *
* Memory Pools * YESYESYESYES * Fast and safe but it can handle fixed size objects only, you may have * multiple memory pools however. *
* C-Runtime * YESNONONO * Unsafe because fragmentation, not constant time, cannot be used * from IRQ handlers and not thread safe. The C runtime must also be * modified in order to work with the other allocators. *
*
* When designing a system it is recommended to proceed as follow: * -# Use static objects and initializers whenever possible. * -# Where dynamic allocation is required without have to free the allocated * memory then use the Core Memory Manager allocation APIs. * -# Where dynamic allocation is required evaluate if one or more memory * pools can be used. * -# If all the above points do not satisfy your requirements then use the * heap allocator. * -# Consider the C-runtime allocator only for legacy code. * . */ href='#n80'>80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278