tool_memory.h 950 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * @file tool_memory.h
  3. * @brief 实现内存管理相关的函数
  4. * This file implements routines for memory management.
  5. * @version 0.1
  6. * @date 2021-09-17
  7. *
  8. * @copyright Copyright (c) 2021
  9. *
  10. */
  11. #ifndef __TOOL_MEMORY_H__
  12. #define __TOOL_MEMORY_H__
  13. #include "csocp_config.h"
  14. /** 分配内存 Allocate memory */
  15. void c_mem_create(void **p_ptr, /**< 指针:指向输入数据 Pointer to input data */
  16. c_int size, /**< 分配内存大小 Size of allocated memory */
  17. c_int ifzero /**< 是否用0初始化 Whether to initialize by zeros */
  18. );
  19. /** 释放内存 Free memory */
  20. void c_mem_free(void **p_ptr /**< 指针:指向输入数据 Pointer to input data */
  21. );
  22. #define CSOCP_INIT(ptr, num) c_mem_create((void **)&(ptr), sizeof(*(ptr)) * (num), 0)
  23. #define CSOCP_INITZ(ptr, num) c_mem_create((void **)&(ptr), sizeof(*(ptr)) * (num), 1)
  24. #define CSOCP_FREE(ptr) c_mem_free((void **)&(ptr))
  25. #endif