#include <stdlib.h>#include <string.h>#include "q_malloc.h"#include "../dprint.h"#include "../globals.h"#include "../statistics.h"

Go to the source code of this file.
Defines | |
| #define | FRAG_CLEAR_USED(f) |
| #define | FRAG_END(f) |
| #define | FRAG_MARK_USED(f) |
| #define | FRAG_NEXT(f) |
| #define | FRAG_OVERHEAD (sizeof(struct qm_frag)+sizeof(struct qm_frag_end)) |
| #define | FRAG_PREV(f) |
| #define | FRAG_WAS_USED(f) (1) |
| #define | GET_HASH(s) |
| #define | MEM_FRAG_AVOIDANCE |
| #define | PREV_FRAG_END(f) ((struct qm_frag_end*)((char*)(f)-sizeof(struct qm_frag_end))) |
| #define | q_malloc |
| #define | ROUNDDOWN(s) ((s)&ROUNDTO_MASK) |
| #define | ROUNDTO_MASK (~((unsigned long)ROUNDTO-1)) |
| #define | ROUNDUP(s) (((s)+(ROUNDTO-1))&ROUNDTO_MASK) |
| #define | UN_HASH(h) |
Functions | |
| static unsigned long | big_hash_idx (unsigned long s) |
| static void | qm_detach_free (struct qm_block *qm, struct qm_frag *frag) |
| static struct qm_frag * | qm_find_free (struct qm_block *qm, unsigned long size, int *h) |
| void | qm_free (struct qm_block *qm, void *p) |
| void | qm_info (struct qm_block *qm, struct mem_info *info) |
| static void | qm_insert_free (struct qm_block *qm, struct qm_frag *frag) |
| void * | qm_malloc (struct qm_block *qm, unsigned long size) |
| struct qm_block * | qm_malloc_init (char *address, unsigned long size) |
| void * | qm_realloc (struct qm_block *qm, void *p, unsigned long size) |
| void | qm_status (struct qm_block *qm) |
| static int | split_frag (struct qm_block *qm, struct qm_frag *f, unsigned long new_size) |
| #define FRAG_CLEAR_USED | ( | f | ) |
| #define FRAG_END | ( | f | ) |
Value:
((struct qm_frag_end*)((char*)(f)+sizeof(struct qm_frag)+ \ (f)->size))
Definition at line 51 of file q_malloc.c.
Referenced by qm_detach_free(), qm_free(), qm_insert_free(), qm_realloc(), qm_status(), and split_frag().
| #define FRAG_MARK_USED | ( | f | ) |
Definition at line 96 of file q_malloc.c.
| #define FRAG_NEXT | ( | f | ) |
Value:
((struct qm_frag*)((char*)(f)+sizeof(struct qm_frag)+(f)->size+ \ sizeof(struct qm_frag_end)))
Definition at line 55 of file q_malloc.c.
Referenced by qm_free(), qm_realloc(), and qm_status().
| #define FRAG_OVERHEAD (sizeof(struct qm_frag)+sizeof(struct qm_frag_end)) |
Definition at line 68 of file q_malloc.c.
Referenced by qm_free(), qm_malloc_init(), qm_realloc(), and split_frag().
| #define FRAG_PREV | ( | f | ) |
Value:
( (struct qm_frag*) ( ((char*)(f)-sizeof(struct qm_frag_end))- \ ((struct qm_frag_end*)((char*)(f)-sizeof(struct qm_frag_end)))->size- \ sizeof(struct qm_frag) ) )
Definition at line 59 of file q_malloc.c.
Referenced by qm_free().
| #define FRAG_WAS_USED | ( | f | ) | (1) |
| #define GET_HASH | ( | s | ) |
Value:
( ((unsigned long)(s)<=QM_MALLOC_OPTIMIZE)?\ (unsigned long)(s)/ROUNDTO: \ QM_MALLOC_OPTIMIZE/ROUNDTO+big_hash_idx((s))- \ QM_MALLOC_OPTIMIZE_FACTOR+1 )
Definition at line 83 of file q_malloc.c.
Referenced by qm_find_free(), qm_free(), qm_insert_free(), and qm_realloc().
| #define MEM_FRAG_AVOIDANCE |
Definition at line 105 of file q_malloc.c.
| #define PREV_FRAG_END | ( | f | ) | ((struct qm_frag_end*)((char*)(f)-sizeof(struct qm_frag_end))) |
Definition at line 64 of file q_malloc.c.
| #define q_malloc |
Definition at line 39 of file q_malloc.c.
| #define ROUNDTO_MASK (~((unsigned long)ROUNDTO-1)) |
Definition at line 71 of file q_malloc.c.
Definition at line 72 of file q_malloc.c.
Referenced by qm_malloc(), qm_malloc_init(), and qm_realloc().
| #define UN_HASH | ( | h | ) |
Value:
( ((unsigned long)(h)<=(QM_MALLOC_OPTIMIZE/ROUNDTO))?\ (unsigned long)(h)*ROUNDTO: \ 1UL<<((h)-QM_MALLOC_OPTIMIZE/ROUNDTO+\ QM_MALLOC_OPTIMIZE_FACTOR-1)\ )
Definition at line 88 of file q_malloc.c.
Referenced by qm_status().
| static unsigned long big_hash_idx | ( | unsigned long | s | ) | [inline, static] |
Definition at line 110 of file q_malloc.c.
Definition at line 255 of file q_malloc.c.
References FRAG_END, qm_frag::nxt_free, and qm_frag::u.
Referenced by qm_free(), qm_malloc(), and qm_realloc().
| static struct qm_frag* qm_find_free | ( | struct qm_block * | qm, | |
| unsigned long | size, | |||
| int * | h | |||
| ) | [static, read] |
Definition at line 275 of file q_malloc.c.
References qm_block::free_hash, GET_HASH, hash, qm_frag_lnk::head, qm_frag::nxt_free, QM_HASH_SIZE, qm_frag::size, and qm_frag::u.
Referenced by qm_malloc().
| void qm_free | ( | struct qm_block * | qm, | |
| void * | p | |||
| ) |
Definition at line 416 of file q_malloc.c.
References qm_block::first_frag, FRAG_END, FRAG_NEXT, FRAG_OVERHEAD, FRAG_PREV, qm_block::free_hash, GET_HASH, qm_frag::is_free, qm_block::last_frag_end, LM_CRIT, LM_GEN1, LM_WARN, memlog, qm_frag_lnk::no, qm_detach_free(), qm_insert_free(), qm_block::real_used, qm_frag::size, qm_frag::u, and qm_block::used.
Referenced by qm_malloc(), and qm_realloc().
Definition at line 688 of file q_malloc.c.
References mem_info::free, qm_block::free_hash, qm_block::max_real_used, mem_info::max_used, mem_info::min_frag, MIN_FRAG_SIZE, qm_frag_lnk::no, QM_HASH_SIZE, mem_info::real_used, qm_block::real_used, qm_block::size, mem_info::total_frags, mem_info::total_size, qm_block::used, and mem_info::used.
Definition at line 162 of file q_malloc.c.
References FRAG_END, qm_block::free_hash, GET_HASH, hash, qm_frag_lnk::head, qm_frag_lnk::no, qm_frag::nxt_free, qm_frag::size, and qm_frag::u.
Referenced by qm_free(), qm_malloc_init(), and split_frag().
| void* qm_malloc | ( | struct qm_block * | qm, | |
| unsigned long | size | |||
| ) |
Definition at line 352 of file q_malloc.c.
References qm_block::free_hash, hash, qm_frag::is_free, LM_GEN1, qm_block::max_real_used, memlog, qm_frag_lnk::no, qm_detach_free(), qm_find_free(), qm_free(), qm_block::real_used, ROUNDUP, qm_frag::size, qm_block::size, split_frag(), qm_frag::u, and qm_block::used.
Referenced by qm_realloc(), and split_frag().
| struct qm_block* qm_malloc_init | ( | char * | address, | |
| unsigned long | size | |||
| ) | [read] |
Definition at line 185 of file q_malloc.c.
References qm_block::first_frag, FRAG_OVERHEAD, qm_block::free_hash, qm_frag_lnk::head, qm_block::last_frag_end, LM_DBG, qm_block::max_real_used, MIN_FRAG_SIZE, qm_frag::nxt_free, qm_frag_end::prev_free, QM_HASH_SIZE, qm_insert_free(), QM_MALLOC_OPTIMIZE, qm_block::real_used, ROUNDDOWN, ROUNDTO, ROUNDUP, qm_frag_end::size, qm_frag::size, qm_block::size, qm_frag_lnk::tail, and qm_frag::u.
Referenced by init_pkg_mallocs().
| void* qm_realloc | ( | struct qm_block * | qm, | |
| void * | p, | |||
| unsigned long | size | |||
| ) |
Definition at line 500 of file q_malloc.c.
References qm_block::first_frag, FRAG_END, FRAG_NEXT, FRAG_OVERHEAD, qm_block::free_hash, GET_HASH, qm_frag::is_free, qm_block::last_frag_end, LM_CRIT, LM_GEN1, memlog, qm_frag_lnk::no, qm_detach_free(), qm_free(), qm_malloc(), qm_block::real_used, ROUNDUP, qm_frag::size, split_frag(), qm_frag::u, and qm_block::used.
| void qm_status | ( | struct qm_block * | qm | ) |
Definition at line 623 of file q_malloc.c.
References qm_block::first_frag, FRAG_END, FRAG_NEXT, FRAG_WAS_USED, qm_block::free_hash, qm_frag_lnk::head, qm_frag::is_free, qm_block::last_frag_end, LM_CRIT, LM_GEN1, qm_block::max_real_used, memlog, qm_frag_lnk::no, qm_frag::nxt_free, QM_HASH_SIZE, QM_MALLOC_OPTIMIZE, qm_block::real_used, ROUNDTO, qm_frag::size, qm_block::size, qm_frag::u, UN_HASH, and qm_block::used.
| static int split_frag | ( | struct qm_block * | qm, | |
| struct qm_frag * | f, | |||
| unsigned long | new_size | |||
| ) | [inline, static] |
Definition at line 305 of file q_malloc.c.
References FRAG_CLEAR_USED, FRAG_END, FRAG_OVERHEAD, MIN_FRAG_SIZE, qm_insert_free(), qm_malloc(), QM_MALLOC_OPTIMIZE, qm_block::real_used, qm_frag_end::size, and qm_frag::size.
Referenced by qm_malloc(), and qm_realloc().
1.5.6