Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

zalloc.h

Go to the documentation of this file.
00001 /*
00002  * $Id: zalloc.h,v 1.5 2005/08/02 12:12:59 daichik Exp $
00003  *
00004  * Copyright (c) 2002-2003, Raphael Manfredi
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *----------------------------------------------------------------------
00024  */
00025 
00036 #ifndef _zalloc_h_
00037 #define _zalloc_h_
00038 
00039 #include <glib.h>
00040 
00041 #define ZALLOC_ALIGNBYTES   MEM_ALIGNBYTES
00042 
00043 /*
00044  * Object size rounding.
00045  */
00046 #define ZALLOC_MASK (ZALLOC_ALIGNBYTES - 1)
00047 #define zalloc_round(s) \
00048     ((gulong) (((gulong) (s) + ZALLOC_MASK) & ~ZALLOC_MASK))
00049 
00061 struct subzone;
00062 
00063 typedef struct zone {           /* Zone descriptor */
00064     gchar **zn_free;            
00065     struct subzone *zn_next;    
00066     gpointer zn_arena;          
00067     gint zn_refcnt;             
00068     gint zn_size;               
00069     gint zn_hint;               
00070     gint zn_cnt;                
00071 } zone_t;
00072 
00073 #define zcount(z)   ((z)->zn_cnt)   
00075 /*
00076  * Memory allocation routines.
00077  */
00078 
00079 zone_t *zcreate(gint, gint);
00080 zone_t *zget(gint, gint);
00081 void zdestroy(zone_t *zone);
00082 
00083 /*
00084  * Under REMAP_ZALLOC control, those routines are remapped to malloc/free.
00085  * Under TRACK_ZALLOC, we keep track of the allocation places.
00086  */
00087 
00088 #if defined(USE_DMALLOC) && !defined(REMAP_ZALLOC)
00089 #define REMAP_ZALLOC
00090 #endif
00091 
00092 #ifdef REMAP_ZALLOC
00093 
00094 #ifdef TRACK_ZALLOC
00095 #error "TRACK_ZALLOC and REMAP_ZALLOC are mutually exclusive"
00096 #endif
00097 
00098 #define zalloc(z)   g_malloc((z)->zn_size)
00099 #define zfree(z,o)  g_free(o)
00100 
00101 #else   /* !REMAP_ZALLOC */
00102 
00103 gpointer zalloc(zone_t *);
00104 void zfree(zone_t *, gpointer);
00105 
00106 #endif  /* REMAP_ZALLOC */
00107 
00108 #ifdef TRACK_ZALLOC
00109 
00110 #define zalloc(z)   zalloc_track(z, __FILE__, __LINE__)
00111 
00112 gpointer zalloc_track(zone_t *z, gchar *file, gint line);
00113 
00114 #endif  /* TRACK_ZALLOC */
00115 
00116 #endif /* _zalloc_h_ */
00117 

Generated on Sun Feb 12 10:49:58 2006 for Gtk-Gnutella by doxygen 1.3.6