meminfo.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**************************************************************************
  2. **
  3. ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  4. **
  5. ** Meschach Library
  6. **
  7. ** This Meschach Library is provided "as is" without any express
  8. ** or implied warranty of any kind with respect to this software.
  9. ** In particular the authors shall not be liable for any direct,
  10. ** indirect, special, incidental or consequential damages arising
  11. ** in any way from use of the software.
  12. **
  13. ** Everyone is granted permission to copy, modify and redistribute this
  14. ** Meschach Library, provided:
  15. ** 1. All copies contain this copyright notice.
  16. ** 2. All modified copies shall carry a notice stating who
  17. ** made the last modification and the date of such modification.
  18. ** 3. No charge is made for this software or works derived from it.
  19. ** This clause shall not be construed as constraining other software
  20. ** distributed on the same medium as this software, nor is a
  21. ** distribution fee considered a charge.
  22. **
  23. ***************************************************************************/
  24. /* meminfo.h 26/08/93 */
  25. /* changed 11/12/93 */
  26. #ifndef MEM_INFOH
  27. #define MEM_INFOH
  28. /* for hash table in mem_stat.c */
  29. /* Note: the hash size should be a prime, or at very least odd */
  30. #define MEM_HASHSIZE 509
  31. #define MEM_HASHSIZE_FILE "meminfo.h"
  32. /* default: memory information is off */
  33. /* set it to 1 if you want it all the time */
  34. #define MEM_SWITCH_ON_DEF 0
  35. /* available standard types */
  36. #define TYPE_NULL (-1)
  37. #define TYPE_MAT 0
  38. #define TYPE_BAND 1
  39. #define TYPE_PERM 2
  40. #define TYPE_VEC 3
  41. #define TYPE_IVEC 4
  42. #ifdef SPARSE
  43. #define TYPE_ITER 5
  44. #define TYPE_SPROW 6
  45. #define TYPE_SPMAT 7
  46. #endif
  47. #ifdef COMPLEX
  48. #ifdef SPARSE
  49. #define TYPE_ZVEC 8
  50. #define TYPE_ZMAT 9
  51. #else
  52. #define TYPE_ZVEC 5
  53. #define TYPE_ZMAT 6
  54. #endif
  55. #endif
  56. /* structure for memory information */
  57. typedef struct {
  58. long bytes; /* # of allocated bytes for each type (summary) */
  59. int numvar; /* # of allocated variables for each type */
  60. } MEM_ARRAY;
  61. #ifdef ANSI_C
  62. int mem_info_is_on(void);
  63. int mem_info_on(int sw);
  64. long mem_info_bytes(int type,int list);
  65. int mem_info_numvar(int type,int list);
  66. void mem_info_file(FILE * fp,int list);
  67. void mem_bytes_list(int type,int old_size,int new_size,
  68. int list);
  69. void mem_numvar_list(int type, int num, int list);
  70. #ifndef THREADSAFE
  71. int mem_stat_reg_list(void **var,int type,int list,char *fname,int line);
  72. int mem_stat_mark(int mark);
  73. int mem_stat_free_list(int mark,int list);
  74. int mem_stat_show_mark(void);
  75. void mem_stat_dump(FILE *fp,int list);
  76. int mem_attach_list(int list,int ntypes,char *type_names[],
  77. int (*free_funcs[])(), MEM_ARRAY info_sum[]);
  78. int mem_free_vars(int list);
  79. int mem_is_list_attached(int list);
  80. void mem_dump_list(FILE *fp,int list);
  81. int mem_stat_reg_vars(int list,int type,char *fname,int line,...);
  82. #endif /* THREADSAFE */
  83. #else
  84. int mem_info_is_on();
  85. int mem_info_on();
  86. long mem_info_bytes();
  87. int mem_info_numvar();
  88. void mem_info_file();
  89. void mem_bytes_list();
  90. void mem_numvar_list();
  91. #ifndef THREADSAFE
  92. int mem_stat_reg_list();
  93. int mem_stat_mark();
  94. int mem_stat_free_list();
  95. int mem_stat_show_mark();
  96. void mem_stat_dump();
  97. int mem_attach_list();
  98. int mem_free_vars();
  99. int mem_is_list_attached();
  100. void mem_dump_list();
  101. int mem_stat_reg_vars();
  102. #endif /* THREADSAFE */
  103. #endif
  104. /* macros */
  105. #define mem_info() mem_info_file(stdout,0)
  106. #ifndef THREADSAFE
  107. #define mem_stat_reg(var,type) mem_stat_reg_list((void **)var,type,0,__FILE__,__LINE__)
  108. #define MEM_STAT_REG(var,type) mem_stat_reg_list((void **)&(var),type,0,__FILE__,__LINE__)
  109. #define mem_stat_free(mark) mem_stat_free_list(mark,0)
  110. #else
  111. #define mem_stat_reg(var,type)
  112. #define MEM_STAT_REG(var,type)
  113. #define mem_stat_free(mark)
  114. #endif
  115. #define mem_bytes(type,old_size,new_size) \
  116. mem_bytes_list(type,old_size,new_size,0)
  117. #define mem_numvar(type,num) mem_numvar_list(type,num,0)
  118. /* internal type */
  119. typedef struct {
  120. char **type_names; /* array of names of types (strings) */
  121. int (**free_funcs)(); /* array of functions for releasing types */
  122. unsigned ntypes; /* max number of types */
  123. MEM_ARRAY *info_sum; /* local array for keeping track of memory */
  124. } MEM_CONNECT;
  125. /* max number of lists of types */
  126. #define MEM_CONNECT_MAX_LISTS 5
  127. #endif