mem.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /*
  2. * File : mem.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2008-7-12 Bernard the first version
  23. * 2010-06-09 Bernard fix the end stub of heap
  24. * fix memory check in rt_realloc function
  25. * 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
  26. * 2010-10-14 Bernard fix rt_realloc issue when realloc a NULL pointer.
  27. * 2017-07-14 armink fix rt_realloc issue when new size is 0
  28. */
  29. /*
  30. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
  31. * All rights reserved.
  32. *
  33. * Redistribution and use in source and binary forms, with or without modification,
  34. * are permitted provided that the following conditions are met:
  35. *
  36. * 1. Redistributions of source code must retain the above copyright notice,
  37. * this list of conditions and the following disclaimer.
  38. * 2. Redistributions in binary form must reproduce the above copyright notice,
  39. * this list of conditions and the following disclaimer in the documentation
  40. * and/or other materials provided with the distribution.
  41. * 3. The name of the author may not be used to endorse or promote products
  42. * derived from this software without specific prior written permission.
  43. *
  44. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  45. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  46. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  47. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  48. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  49. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  50. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  51. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  52. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  53. * OF SUCH DAMAGE.
  54. *
  55. * This file is part of the lwIP TCP/IP stack.
  56. *
  57. * Author: Adam Dunkels <adam@sics.se>
  58. * Simon Goldschmidt
  59. *
  60. */
  61. #include <rthw.h>
  62. #include <rtthread.h>
  63. #ifndef RT_USING_MEMHEAP_AS_HEAP
  64. /* #define RT_MEM_DEBUG */
  65. #define RT_MEM_STATS
  66. #if defined (RT_USING_HEAP) && defined (RT_USING_SMALL_MEM)
  67. #ifdef RT_USING_HOOK
  68. static void (*rt_malloc_hook)(void *ptr, rt_size_t size);
  69. static void (*rt_free_hook)(void *ptr);
  70. /**
  71. * @addtogroup Hook
  72. */
  73. /**@{*/
  74. /**
  75. * This function will set a hook function, which will be invoked when a memory
  76. * block is allocated from heap memory.
  77. *
  78. * @param hook the hook function
  79. */
  80. void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size))
  81. {
  82. rt_malloc_hook = hook;
  83. }
  84. /**
  85. * This function will set a hook function, which will be invoked when a memory
  86. * block is released to heap memory.
  87. *
  88. * @param hook the hook function
  89. */
  90. void rt_free_sethook(void (*hook)(void *ptr))
  91. {
  92. rt_free_hook = hook;
  93. }
  94. /**@}*/
  95. #endif
  96. #define HEAP_MAGIC 0x1ea0
  97. struct heap_mem
  98. {
  99. /* magic and used flag */
  100. rt_uint16_t magic;
  101. rt_uint16_t used;
  102. rt_size_t next, prev;
  103. };
  104. /** pointer to the heap: for alignment, heap_ptr is now a pointer instead of an array */
  105. static rt_uint8_t *heap_ptr;
  106. /** the last entry, always unused! */
  107. static struct heap_mem *heap_end;
  108. #define MIN_SIZE 12
  109. #define MIN_SIZE_ALIGNED RT_ALIGN(MIN_SIZE, RT_ALIGN_SIZE)
  110. #define SIZEOF_STRUCT_MEM RT_ALIGN(sizeof(struct heap_mem), RT_ALIGN_SIZE)
  111. static struct heap_mem *lfree; /* pointer to the lowest free block */
  112. static struct rt_semaphore heap_sem;
  113. static rt_size_t mem_size_aligned;
  114. #ifdef RT_MEM_STATS
  115. static rt_size_t used_mem, max_mem;
  116. #endif
  117. static void plug_holes(struct heap_mem *mem)
  118. {
  119. struct heap_mem *nmem;
  120. struct heap_mem *pmem;
  121. RT_ASSERT((rt_uint8_t *)mem >= heap_ptr);
  122. RT_ASSERT((rt_uint8_t *)mem < (rt_uint8_t *)heap_end);
  123. RT_ASSERT(mem->used == 0);
  124. /* plug hole forward */
  125. nmem = (struct heap_mem *)&heap_ptr[mem->next];
  126. if (mem != nmem &&
  127. nmem->used == 0 &&
  128. (rt_uint8_t *)nmem != (rt_uint8_t *)heap_end)
  129. {
  130. /* if mem->next is unused and not end of heap_ptr,
  131. * combine mem and mem->next
  132. */
  133. if (lfree == nmem)
  134. {
  135. lfree = mem;
  136. }
  137. mem->next = nmem->next;
  138. ((struct heap_mem *)&heap_ptr[nmem->next])->prev = (rt_uint8_t *)mem - heap_ptr;
  139. }
  140. /* plug hole backward */
  141. pmem = (struct heap_mem *)&heap_ptr[mem->prev];
  142. if (pmem != mem && pmem->used == 0)
  143. {
  144. /* if mem->prev is unused, combine mem and mem->prev */
  145. if (lfree == mem)
  146. {
  147. lfree = pmem;
  148. }
  149. pmem->next = mem->next;
  150. ((struct heap_mem *)&heap_ptr[mem->next])->prev = (rt_uint8_t *)pmem - heap_ptr;
  151. }
  152. }
  153. /**
  154. * @ingroup SystemInit
  155. *
  156. * This function will initialize system heap memory.
  157. *
  158. * @param begin_addr the beginning address of system heap memory.
  159. * @param end_addr the end address of system heap memory.
  160. */
  161. void rt_system_heap_init(void *begin_addr, void *end_addr)
  162. {
  163. struct heap_mem *mem;
  164. rt_uint32_t begin_align = RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
  165. rt_uint32_t end_align = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_ALIGN_SIZE);
  166. RT_DEBUG_NOT_IN_INTERRUPT;
  167. /* alignment addr */
  168. if ((end_align > (2 * SIZEOF_STRUCT_MEM)) &&
  169. ((end_align - 2 * SIZEOF_STRUCT_MEM) >= begin_align))
  170. {
  171. /* calculate the aligned memory size */
  172. mem_size_aligned = end_align - begin_align - 2 * SIZEOF_STRUCT_MEM;
  173. }
  174. else
  175. {
  176. rt_kprintf("mem init, error begin address 0x%x, and end address 0x%x\n",
  177. (rt_uint32_t)begin_addr, (rt_uint32_t)end_addr);
  178. return;
  179. }
  180. /* point to begin address of heap */
  181. heap_ptr = (rt_uint8_t *)begin_align;
  182. RT_DEBUG_LOG(RT_DEBUG_MEM, ("mem init, heap begin address 0x%x, size %d\n",
  183. (rt_uint32_t)heap_ptr, mem_size_aligned));
  184. /* initialize the start of the heap */
  185. mem = (struct heap_mem *)heap_ptr;
  186. mem->magic = HEAP_MAGIC;
  187. mem->next = mem_size_aligned + SIZEOF_STRUCT_MEM;
  188. mem->prev = 0;
  189. mem->used = 0;
  190. /* initialize the end of the heap */
  191. heap_end = (struct heap_mem *)&heap_ptr[mem->next];
  192. heap_end->magic = HEAP_MAGIC;
  193. heap_end->used = 1;
  194. heap_end->next = mem_size_aligned + SIZEOF_STRUCT_MEM;
  195. heap_end->prev = mem_size_aligned + SIZEOF_STRUCT_MEM;
  196. rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO);
  197. /* initialize the lowest-free pointer to the start of the heap */
  198. lfree = (struct heap_mem *)heap_ptr;
  199. }
  200. /**
  201. * @addtogroup MM
  202. */
  203. /**@{*/
  204. /**
  205. * Allocate a block of memory with a minimum of 'size' bytes.
  206. *
  207. * @param size is the minimum size of the requested block in bytes.
  208. *
  209. * @return pointer to allocated memory or NULL if no free memory was found.
  210. */
  211. void *rt_malloc(rt_size_t size)
  212. {
  213. rt_size_t ptr, ptr2;
  214. struct heap_mem *mem, *mem2;
  215. RT_DEBUG_NOT_IN_INTERRUPT;
  216. if (size == 0)
  217. return RT_NULL;
  218. if (size != RT_ALIGN(size, RT_ALIGN_SIZE))
  219. RT_DEBUG_LOG(RT_DEBUG_MEM, ("malloc size %d, but align to %d\n",
  220. size, RT_ALIGN(size, RT_ALIGN_SIZE)));
  221. else
  222. RT_DEBUG_LOG(RT_DEBUG_MEM, ("malloc size %d\n", size));
  223. /* alignment size */
  224. size = RT_ALIGN(size, RT_ALIGN_SIZE);
  225. if (size > mem_size_aligned)
  226. {
  227. RT_DEBUG_LOG(RT_DEBUG_MEM, ("no memory\n"));
  228. return RT_NULL;
  229. }
  230. /* every data block must be at least MIN_SIZE_ALIGNED long */
  231. if (size < MIN_SIZE_ALIGNED)
  232. size = MIN_SIZE_ALIGNED;
  233. /* take memory semaphore */
  234. rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
  235. for (ptr = (rt_uint8_t *)lfree - heap_ptr;
  236. ptr < mem_size_aligned - size;
  237. ptr = ((struct heap_mem *)&heap_ptr[ptr])->next)
  238. {
  239. mem = (struct heap_mem *)&heap_ptr[ptr];
  240. if ((!mem->used) && (mem->next - (ptr + SIZEOF_STRUCT_MEM)) >= size)
  241. {
  242. /* mem is not used and at least perfect fit is possible:
  243. * mem->next - (ptr + SIZEOF_STRUCT_MEM) gives us the 'user data size' of mem */
  244. if (mem->next - (ptr + SIZEOF_STRUCT_MEM) >=
  245. (size + SIZEOF_STRUCT_MEM + MIN_SIZE_ALIGNED))
  246. {
  247. /* (in addition to the above, we test if another struct heap_mem (SIZEOF_STRUCT_MEM) containing
  248. * at least MIN_SIZE_ALIGNED of data also fits in the 'user data space' of 'mem')
  249. * -> split large block, create empty remainder,
  250. * remainder must be large enough to contain MIN_SIZE_ALIGNED data: if
  251. * mem->next - (ptr + (2*SIZEOF_STRUCT_MEM)) == size,
  252. * struct heap_mem would fit in but no data between mem2 and mem2->next
  253. * @todo we could leave out MIN_SIZE_ALIGNED. We would create an empty
  254. * region that couldn't hold data, but when mem->next gets freed,
  255. * the 2 regions would be combined, resulting in more free memory
  256. */
  257. ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
  258. /* create mem2 struct */
  259. mem2 = (struct heap_mem *)&heap_ptr[ptr2];
  260. mem2->magic = HEAP_MAGIC;
  261. mem2->used = 0;
  262. mem2->next = mem->next;
  263. mem2->prev = ptr;
  264. /* and insert it between mem and mem->next */
  265. mem->next = ptr2;
  266. mem->used = 1;
  267. if (mem2->next != mem_size_aligned + SIZEOF_STRUCT_MEM)
  268. {
  269. ((struct heap_mem *)&heap_ptr[mem2->next])->prev = ptr2;
  270. }
  271. #ifdef RT_MEM_STATS
  272. used_mem += (size + SIZEOF_STRUCT_MEM);
  273. if (max_mem < used_mem)
  274. max_mem = used_mem;
  275. #endif
  276. }
  277. else
  278. {
  279. /* (a mem2 struct does no fit into the user data space of mem and mem->next will always
  280. * be used at this point: if not we have 2 unused structs in a row, plug_holes should have
  281. * take care of this).
  282. * -> near fit or excact fit: do not split, no mem2 creation
  283. * also can't move mem->next directly behind mem, since mem->next
  284. * will always be used at this point!
  285. */
  286. mem->used = 1;
  287. #ifdef RT_MEM_STATS
  288. used_mem += mem->next - ((rt_uint8_t *)mem - heap_ptr);
  289. if (max_mem < used_mem)
  290. max_mem = used_mem;
  291. #endif
  292. }
  293. /* set memory block magic */
  294. mem->magic = HEAP_MAGIC;
  295. if (mem == lfree)
  296. {
  297. /* Find next free block after mem and update lowest free pointer */
  298. while (lfree->used && lfree != heap_end)
  299. lfree = (struct heap_mem *)&heap_ptr[lfree->next];
  300. RT_ASSERT(((lfree == heap_end) || (!lfree->used)));
  301. }
  302. rt_sem_release(&heap_sem);
  303. RT_ASSERT((rt_uint32_t)mem + SIZEOF_STRUCT_MEM + size <= (rt_uint32_t)heap_end);
  304. RT_ASSERT((rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0);
  305. RT_ASSERT((((rt_uint32_t)mem) & (RT_ALIGN_SIZE - 1)) == 0);
  306. RT_DEBUG_LOG(RT_DEBUG_MEM,
  307. ("allocate memory at 0x%x, size: %d\n",
  308. (rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM),
  309. (rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
  310. RT_OBJECT_HOOK_CALL(rt_malloc_hook,
  311. (((void *)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM)), size));
  312. /* return the memory data except mem struct */
  313. return (rt_uint8_t *)mem + SIZEOF_STRUCT_MEM;
  314. }
  315. }
  316. rt_sem_release(&heap_sem);
  317. return RT_NULL;
  318. }
  319. RTM_EXPORT(rt_malloc);
  320. /**
  321. * This function will change the previously allocated memory block.
  322. *
  323. * @param rmem pointer to memory allocated by rt_malloc
  324. * @param newsize the required new size
  325. *
  326. * @return the changed memory block address
  327. */
  328. void *rt_realloc(void *rmem, rt_size_t newsize)
  329. {
  330. rt_size_t size;
  331. rt_size_t ptr, ptr2;
  332. struct heap_mem *mem, *mem2;
  333. void *nmem;
  334. RT_DEBUG_NOT_IN_INTERRUPT;
  335. /* alignment size */
  336. newsize = RT_ALIGN(newsize, RT_ALIGN_SIZE);
  337. if (newsize > mem_size_aligned)
  338. {
  339. RT_DEBUG_LOG(RT_DEBUG_MEM, ("realloc: out of memory\n"));
  340. return RT_NULL;
  341. }
  342. else if (newsize == 0)
  343. {
  344. rt_free(rmem);
  345. return RT_NULL;
  346. }
  347. /* allocate a new memory block */
  348. if (rmem == RT_NULL)
  349. return rt_malloc(newsize);
  350. rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
  351. if ((rt_uint8_t *)rmem < (rt_uint8_t *)heap_ptr ||
  352. (rt_uint8_t *)rmem >= (rt_uint8_t *)heap_end)
  353. {
  354. /* illegal memory */
  355. rt_sem_release(&heap_sem);
  356. return rmem;
  357. }
  358. mem = (struct heap_mem *)((rt_uint8_t *)rmem - SIZEOF_STRUCT_MEM);
  359. ptr = (rt_uint8_t *)mem - heap_ptr;
  360. size = mem->next - ptr - SIZEOF_STRUCT_MEM;
  361. if (size == newsize)
  362. {
  363. /* the size is the same as */
  364. rt_sem_release(&heap_sem);
  365. return rmem;
  366. }
  367. if (newsize + SIZEOF_STRUCT_MEM + MIN_SIZE < size)
  368. {
  369. /* split memory block */
  370. #ifdef RT_MEM_STATS
  371. used_mem -= (size - newsize);
  372. #endif
  373. ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
  374. mem2 = (struct heap_mem *)&heap_ptr[ptr2];
  375. mem2->magic = HEAP_MAGIC;
  376. mem2->used = 0;
  377. mem2->next = mem->next;
  378. mem2->prev = ptr;
  379. mem->next = ptr2;
  380. if (mem2->next != mem_size_aligned + SIZEOF_STRUCT_MEM)
  381. {
  382. ((struct heap_mem *)&heap_ptr[mem2->next])->prev = ptr2;
  383. }
  384. plug_holes(mem2);
  385. rt_sem_release(&heap_sem);
  386. return rmem;
  387. }
  388. rt_sem_release(&heap_sem);
  389. /* expand memory */
  390. nmem = rt_malloc(newsize);
  391. if (nmem != RT_NULL) /* check memory */
  392. {
  393. rt_memcpy(nmem, rmem, size < newsize ? size : newsize);
  394. rt_free(rmem);
  395. }
  396. return nmem;
  397. }
  398. RTM_EXPORT(rt_realloc);
  399. /**
  400. * This function will contiguously allocate enough space for count objects
  401. * that are size bytes of memory each and returns a pointer to the allocated
  402. * memory.
  403. *
  404. * The allocated memory is filled with bytes of value zero.
  405. *
  406. * @param count number of objects to allocate
  407. * @param size size of the objects to allocate
  408. *
  409. * @return pointer to allocated memory / NULL pointer if there is an error
  410. */
  411. void *rt_calloc(rt_size_t count, rt_size_t size)
  412. {
  413. void *p;
  414. RT_DEBUG_NOT_IN_INTERRUPT;
  415. /* allocate 'count' objects of size 'size' */
  416. p = rt_malloc(count * size);
  417. /* zero the memory */
  418. if (p)
  419. rt_memset(p, 0, count * size);
  420. return p;
  421. }
  422. RTM_EXPORT(rt_calloc);
  423. /**
  424. * This function will release the previously allocated memory block by
  425. * rt_malloc. The released memory block is taken back to system heap.
  426. *
  427. * @param rmem the address of memory which will be released
  428. */
  429. void rt_free(void *rmem)
  430. {
  431. struct heap_mem *mem;
  432. RT_DEBUG_NOT_IN_INTERRUPT;
  433. if (rmem == RT_NULL)
  434. return;
  435. RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0);
  436. RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
  437. (rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
  438. RT_OBJECT_HOOK_CALL(rt_free_hook, (rmem));
  439. if ((rt_uint8_t *)rmem < (rt_uint8_t *)heap_ptr ||
  440. (rt_uint8_t *)rmem >= (rt_uint8_t *)heap_end)
  441. {
  442. RT_DEBUG_LOG(RT_DEBUG_MEM, ("illegal memory\n"));
  443. return;
  444. }
  445. /* Get the corresponding struct heap_mem ... */
  446. mem = (struct heap_mem *)((rt_uint8_t *)rmem - SIZEOF_STRUCT_MEM);
  447. RT_DEBUG_LOG(RT_DEBUG_MEM,
  448. ("release memory 0x%x, size: %d\n",
  449. (rt_uint32_t)rmem,
  450. (rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
  451. /* protect the heap from concurrent access */
  452. rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
  453. /* ... which has to be in a used state ... */
  454. RT_ASSERT(mem->used);
  455. RT_ASSERT(mem->magic == HEAP_MAGIC);
  456. /* ... and is now unused. */
  457. mem->used = 0;
  458. mem->magic = HEAP_MAGIC;
  459. if (mem < lfree)
  460. {
  461. /* the newly freed struct is now the lowest */
  462. lfree = mem;
  463. }
  464. #ifdef RT_MEM_STATS
  465. used_mem -= (mem->next - ((rt_uint8_t *)mem - heap_ptr));
  466. #endif
  467. /* finally, see if prev or next are free also */
  468. plug_holes(mem);
  469. rt_sem_release(&heap_sem);
  470. }
  471. RTM_EXPORT(rt_free);
  472. #ifdef RT_MEM_STATS
  473. void rt_memory_info(rt_uint32_t *total,
  474. rt_uint32_t *used,
  475. rt_uint32_t *max_used)
  476. {
  477. if (total != RT_NULL)
  478. *total = mem_size_aligned;
  479. if (used != RT_NULL)
  480. *used = used_mem;
  481. if (max_used != RT_NULL)
  482. *max_used = max_mem;
  483. }
  484. #ifdef RT_USING_FINSH
  485. #include <finsh.h>
  486. void list_mem(void)
  487. {
  488. rt_kprintf("total memory: %d\n", mem_size_aligned);
  489. rt_kprintf("used memory : %d\n", used_mem);
  490. rt_kprintf("maximum allocated memory: %d\n", max_mem);
  491. }
  492. FINSH_FUNCTION_EXPORT(list_mem, list memory usage information)
  493. #endif
  494. #endif
  495. /**@}*/
  496. #endif /* end of RT_USING_HEAP */
  497. #endif /* end of RT_USING_MEMHEAP_AS_HEAP */