swheap.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /************************************************************************
  2. * AUTHOR: NiuJiuRu
  3. * FILENAME: swheap.c
  4. * DESCRIPTION: 可分块/可跟踪内存泄漏位置的内存管理全局堆
  5. * NOTE:
  6. * HISTORY:
  7. * 1, [2010-09-27] created by NiuJiuRu
  8. ***********************************************************************/
  9. #include "swapi.h"
  10. #include "swmem.h"
  11. // 内存管理模块的全局堆
  12. void *g_hSwHeap = NULL;
  13. /* 初试化内存管理模块的全局堆, align = 1, 2, 4, 8, 16, ... */
  14. bool sw_heap_init(char *buf, int size, int align)
  15. {
  16. g_hSwHeap = sw_mem_create(buf, size, align);
  17. return (g_hSwHeap != NULL);
  18. }
  19. /* 释放内存管理模块的全局堆 */
  20. void sw_heap_exit()
  21. {
  22. sw_mem_destroy(g_hSwHeap);
  23. g_hSwHeap = NULL;
  24. }
  25. /* 检查全局堆的内存使用情况, 并返回历史上最大消耗过的内存数 */
  26. int sw_heap_check(PMemCheckCallback proc, void *lpParameter)
  27. {
  28. return sw_mem_check(g_hSwHeap, proc, lpParameter);
  29. }
  30. /* 获得全局堆总的内存大小 */
  31. int sw_heap_getTotalSize()
  32. {
  33. return sw_mem_getTotalSize(g_hSwHeap);
  34. }