Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #if !defined(q_malloc_h) && !defined(F_MALLOC)
00036 #define q_malloc_h
00037
00038 #include "meminfo.h"
00039
00040
00041 #ifdef DBG_QM_MALLOC
00042 #if defined(__CPU_sparc64) || defined(__CPU_sparc)
00043
00044
00045
00046 #define ROUNDTO sizeof(long long)
00047 #else
00048 #define ROUNDTO sizeof(void*)
00049
00050 #endif
00051 #else
00052 #define ROUNDTO 16UL
00053
00054
00055
00056 #endif
00057 #define MIN_FRAG_SIZE ROUNDTO
00058
00059
00060
00061 #define QM_MALLOC_OPTIMIZE_FACTOR 14UL
00062 #define QM_MALLOC_OPTIMIZE ((unsigned long)(1UL<<QM_MALLOC_OPTIMIZE_FACTOR))
00063
00064
00065
00066
00067 #define QM_HASH_SIZE ((unsigned long)(QM_MALLOC_OPTIMIZE/ROUNDTO + \
00068 (sizeof(long)*8-QM_MALLOC_OPTIMIZE_FACTOR)+1))
00069
00070
00071
00072
00073
00074
00075 struct qm_frag{
00076 unsigned long size;
00077 union{
00078 struct qm_frag* nxt_free;
00079 long is_free;
00080 }u;
00081 #ifdef DBG_QM_MALLOC
00082 const char* file;
00083 const char* func;
00084 unsigned long line;
00085 unsigned long check;
00086 #endif
00087 };
00088
00089 struct qm_frag_end{
00090 #ifdef DBG_QM_MALLOC
00091 unsigned long check1;
00092 unsigned long check2;
00093 unsigned long reserved1;
00094 unsigned long reserved2;
00095 #endif
00096 unsigned long size;
00097 struct qm_frag* prev_free;
00098 };
00099
00100
00101
00102 struct qm_frag_lnk{
00103 struct qm_frag head;
00104 struct qm_frag_end tail;
00105 unsigned long no;
00106 };
00107
00108
00114 struct qm_block{
00115 unsigned long size;
00116 unsigned long used;
00117 unsigned long real_used;
00118 unsigned long max_real_used;
00119
00120 struct qm_frag* first_frag;
00121 struct qm_frag_end* last_frag_end;
00122
00123 struct qm_frag_lnk free_hash[QM_HASH_SIZE];
00124
00125 };
00126
00127
00128
00129 struct qm_block* qm_malloc_init(char* address, unsigned long size);
00130
00131 #ifdef DBG_QM_MALLOC
00132 void* qm_malloc(struct qm_block*, unsigned long size, const char* file,
00133 const char* func, unsigned int line);
00134 #else
00135 void* qm_malloc(struct qm_block*, unsigned long size);
00136 #endif
00137
00138 #ifdef DBG_QM_MALLOC
00139 void qm_free(struct qm_block*, void* p, const char* file, const char* func,
00140 unsigned int line);
00141 #else
00142 void qm_free(struct qm_block*, void* p);
00143 #endif
00144 #ifdef DBG_QM_MALLOC
00145 void* qm_realloc(struct qm_block*, void* p, unsigned long size,
00146 const char* file, const char* func, unsigned int line);
00147 #else
00148 void* qm_realloc(struct qm_block*, void* p, unsigned long size);
00149 #endif
00150
00151 void qm_status(struct qm_block*);
00152 void qm_check(struct qm_block*);
00153 void qm_info(struct qm_block*, struct mem_info*);
00154
00155 unsigned long qm_available(struct qm_block* qm);
00156
00157 #ifdef DBG_QM_MALLOC
00158 void qm_sums(struct qm_block* qm);
00159 #else
00160 #define qm_sums(v) do{}while(0)
00161 #endif
00162
00163 #endif