#ifndef QMALLOC_H
#define QMALLOC_H

#ifdef __cplusplus
extern "C" {
#endif


typedef struct QMALLOC_LIST {char *data; struct QMALLOC_LIST *next;} QMalloclist;

typedef struct {
	QMalloclist *mlist;
	QMalloclist *mcur;
	int total_leeked;
	int total_allocated;
	int zleft;
	int zupto;
	int chunksize;
	int totused;
	char *file;
	int line;
	int original_chunksize;
	int original_total_allocated;
	int original_upto;
} Qmalloc;
int qmalloc_test(void);
#define qmalloc_new(x) qmalloc_new_do(x,__FILE__,__LINE__)
Qmalloc *qmalloc_new_do(int chunksize, char *file, int line);

void qmalloc_free_all_do(Qmalloc *q, char *file, int line);
void qmalloc_free_blocks_do(Qmalloc *q, char *file, int line);
#define qmalloc_free_all(x) qmalloc_free_all_do(x,__FILE__,__LINE__)
#define qmalloc_free_blocks(x) qmalloc_free_blocks_do(x,__FILE__,__LINE__)
void *qcalloc(Qmalloc *q, int sz);
void *qmalloc2(Qmalloc *q, int sz, int alignby);
void qfree(Qmalloc *q, int s);
void *qmalloc(Qmalloc *q, int sz);
int qtotal_leeked(Qmalloc *q);
void qfreestr(Qmalloc *q, char *s);
char *qstrdup(Qmalloc *q, char *s);
void *qmalloc_aligned(Qmalloc *q, int sz);
void *qmalloc_aligned2(Qmalloc *q, int sz);

#ifdef __cplusplus
}
#endif

#endif


