Newer
Older
libkc / modules / include / kc_memory_mark.h
  1. /**
  2. * @file kc_memory_mark.h
  3. * @brief KC メモリ管理 メモリ状態を扱うサブモジュール (mark)
  4. * @copyright 2003 - 2023 Nomura Kei
  5. * @depends
  6. * kc.h
  7. *
  8. * 本ヘッダファイルを直接 include せず、kc_memory.h を include してください。
  9. */
  10. #ifndef KC_MEMORY_MARK_H
  11. #define KC_MEMORY_MARK_H
  12.  
  13. #include <kc.h>
  14.  
  15. #ifdef __cplusplus
  16. extern "C"
  17. {
  18. namespace kc
  19. {
  20. using namespace std;
  21. #endif
  22.  
  23. /**
  24. * 指定された KcMemoryMark の値が、管理メモリか否かを判定します。
  25. *
  26. * @param mark 判定する KcMemoryMark
  27. * @return true/false (管理メモリ/管理メモリ外)
  28. */
  29. #define KC_MEMORY_IS_MANAGED(mark) ((mark & 0xFFFF0000) == 0x55AA0000)
  30.  
  31. /**
  32. * メモリ状態
  33. */
  34. typedef enum
  35. {
  36. KC_MEMORY_DELETED = 0x55AA0000, //!< 解放済み
  37. KC_MEMORY_ALLOCATED = 0x55AA1111, //!< 確保済み
  38. KC_MEMORY_ALLOCATED_ALIGNED = 0x55AA1155 //!< 確保済み(aligned)
  39. // KC_MEMORY_ALLOCATED_NEW = 0x55AA2222, //!< new により確保済み
  40. // KC_MEMORY_ALLOCATED_NEW_ARRAY = 0x55AA4444 //!< new[] により確保済み
  41. } KcMemoryMark;
  42.  
  43. /**
  44. * 指定されたメモリ状態に対応する文字列表現を返します。
  45. * 返される文字列は、次の通り
  46. * - alloc : malloc, calloc, realloc によりメモリが確保された
  47. * - new : new によりメモリが確保された
  48. * - new[] : new[] によりメモリが確保された
  49. * - delete : 削除済みメモリ
  50. * - other : 不明
  51. *
  52. * @param mark メモリ状態
  53. * @return メモリ状態に対応する文字列表現
  54. */
  55. const char *KcMemoryMark_to_string(int mark);
  56.  
  57. #ifdef __cplusplus
  58. } // namespace kc
  59. } // extern "C"
  60. #endif
  61. #endif // KC_MEMORY_MARK_H