嵌入式(标准C环境下)下通用的内存池的实现---头文件

来源:互联网 发布:软件快捷方式打不开 编辑:程序博客网 时间:2024/06/05 19:49
  1. #ifndef __AVIT_OC_GEN_H__
  2. #define __AVIT_OC_GEN_H__
  3. #ifdef _MSC_VER
  4.     #include "wtypes.h" 
  5.     #include "stdio.h"
  6. #endif
  7. #include "j_gendef.h"
  8. #include "avit_oc_config.h"
  9. #endif  /* __AVIT_OC_GEN_H__ */
  1. #ifndef __AVIT_MEMORY_POOL_H__
  2. #define __AVIT_MEMORY_POOL_H__
  3. #include "avit_oc_gen.h"
  4. #include "j_osp.h"
  5. #include "string.h"
  6. #if defined(__cplusplus)
  7. extern "C" {
  8. #endif
  9. #ifdef _MSC_VER
  10.     #pragma pack(4)
  11. #endif
  12. typedef struct _MemNode
  13. {
  14.     BOOL used;
  15.     UINT32 size;
  16.     UINT8* addr;
  17.     struct _MemNode* last;
  18.     struct _MemNode* next;
  19. }MemNode;
  20. #ifdef _MSC_VER
  21.     #pragma pack()
  22. #endif
  23. INT32 memory_pool_init();
  24. void memory_pool_clear();
  25. void memory_pool_release();
  26. void* memory_pool_malloc(UINT32 size);
  27. void memory_pool_free(void* pAddr);
  28. UINT32 memory_pool_get_peak_use();
  29. UINT32 memory_pool_get_now_use();
  30. UINT32 memory_pool_get_available_size();
  31. void memory_pool_dump();
  32. #if defined(__cplusplus)
  33. }
  34. #endif
  35. #endif  /* __AVIT_MEMORY_POOL_H__ */

 

  1. #ifndef __AVIT_OC_CONFIG_H__
  2. #define __AVIT_OC_CONFIG_H__
  3. #define SIZE_K 1024
  4. #define SIZE_M (1024*1024)
  5. #define PRINT_ENABLE 1
  6. #define CACHE_SIZE (1*SIZE_M)
  7. #define CACHE_RESERVED (256*SIZE_K)
  8. #define CACHE_DEAL (CACHE_SIZE*2+CACHE_RESERVED)
  9. #define MEMORY_POOL_ENABLE 1
  10. #define MEMORY_POOL_COUNTER_ENABLE 1
  11. #define MEMORY_POOL_SIZE_MIN (2*SIZE_M)
  12. #define MEMORY_POOL_SIZE ( (CACHE_DEAL < MEMORY_POOL_SIZE_MIN) ? MEMORY_POOL_SIZE_MIN:CACHE_DEAL )
  13. #endif  /* __AVIT_OC_CONFIG_H__ */