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
00029
00037 #if !defined(f_malloc_h)
00038 #define f_malloc_h
00039
00040 #ifdef DBG_QM_MALLOC
00041 #ifndef DBG_F_MALLOC
00042 #define DBG_F_MALLOC
00043 #endif
00044 #endif
00045
00046 #include "meminfo.h"
00047
00048
00053 #define F_MALLOC_HASH_BITMAP
00054
00055 #ifdef DBG_F_MALLOC
00056 #if defined(__CPU_sparc64) || defined(__CPU_sparc)
00057
00058
00059
00060 #define ROUNDTO sizeof(long long)
00061 #else
00062 #define ROUNDTO sizeof(void*)
00063
00064 #endif
00065 #else
00066 #define ROUNDTO 8UL
00067 #endif
00068 #define MIN_FRAG_SIZE ROUNDTO
00069
00070
00071
00072 #define F_MALLOC_OPTIMIZE_FACTOR 14UL
00073
00074 #define F_MALLOC_OPTIMIZE (1UL<<F_MALLOC_OPTIMIZE_FACTOR)
00075
00076
00077 #define F_HASH_SIZE (F_MALLOC_OPTIMIZE/ROUNDTO + \
00078 (sizeof(long)*8-F_MALLOC_OPTIMIZE_FACTOR)+1)
00079
00080 #ifdef F_MALLOC_HASH_BITMAP
00081 typedef unsigned long fm_hash_bitmap_t;
00082 #define FM_HASH_BMP_BITS (sizeof(fm_hash_bitmap_t)*8)
00083 #define FM_HASH_BMP_SIZE \
00084 ((F_HASH_SIZE+FM_HASH_BMP_BITS-1)/FM_HASH_BMP_BITS)
00085 #endif
00086
00093 struct fm_frag{
00094 unsigned long size;
00095 union{
00096 struct fm_frag* nxt_free;
00097 long reserved;
00098 }u;
00099 #ifdef DBG_F_MALLOC
00100 const char* file;
00101 const char* func;
00102 unsigned long line;
00103 unsigned long check;
00104 #endif
00105 };
00106
00107 struct fm_frag_lnk{
00108 struct fm_frag* first;
00109 unsigned long no;
00110 };
00111
00116 struct fm_block{
00117 unsigned long size;
00118 #if defined(DBG_F_MALLOC) || defined(MALLOC_STATS)
00119 unsigned long used;
00120 unsigned long real_used;
00121 unsigned long max_real_used;
00122 #endif
00123
00124 struct fm_frag* first_frag;
00125 struct fm_frag* last_frag;
00126 #ifdef F_MALLOC_HASH_BITMAP
00127 fm_hash_bitmap_t free_bitmap[FM_HASH_BMP_SIZE];
00128 #endif
00129 struct fm_frag_lnk free_hash[F_HASH_SIZE];
00130 };
00131
00132
00139 struct fm_block* fm_malloc_init(char* address, unsigned long size);
00140
00141
00148 #ifdef DBG_F_MALLOC
00149 void* fm_malloc(struct fm_block* qm, unsigned long size,
00150 const char* file, const char* func, unsigned int line);
00151 #else
00152 void* fm_malloc(struct fm_block* qm, unsigned long size);
00153 #endif
00154
00155
00163 #ifdef DBG_F_MALLOC
00164 void fm_free(struct fm_block* qm, void* p, const char* file, const char* func,
00165 unsigned int line);
00166 #else
00167 void fm_free(struct fm_block* qm, void* p);
00168 #endif
00169
00170
00180 #ifdef DBG_F_MALLOC
00181 void* fm_realloc(struct fm_block* qm, void* p, unsigned long size,
00182 const char* file, const char* func, unsigned int line);
00183 #else
00184 void* fm_realloc(struct fm_block* qm, void* p, unsigned long size);
00185 #endif
00186
00187
00192 void fm_status(struct fm_block* qm);
00193
00194
00203 void fm_info(struct fm_block* qm, struct mem_info* info);
00204
00205
00212 unsigned long fm_available(struct fm_block* qm);
00213
00214
00219 #ifdef DBG_F_MALLOC
00220 void fm_sums(struct fm_block* qm);
00221 #else
00222 #define fm_sums(qm) do{}while(0)
00223 #endif
00224
00225 #endif