2 * Definitions for very simple slab handling
4 * $Id: slab.h,v 1.2 2003/12/03 08:53:36 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #define NITEMS_PER_SLAB 100
30 typedef struct _freed_item {
31 struct _freed_item *next;
34 /* we never free any memory we have allocated, when it is returned to us
35 we just store it in the free list until (hopefully) it gets used again
37 #define SLAB_ALLOC(item, list) \
41 tmp=(char *)g_malloc(NITEMS_PER_SLAB* \
42 ((sizeof(*item) > sizeof(freed_item_t)) ? \
43 sizeof(*item) : sizeof(freed_item_t))); \
44 for(i=0;i<NITEMS_PER_SLAB;i++){ \
46 ((freed_item_t *)((void *)item))->next= \
47 (freed_item_t *)((void *)list); \
50 ((sizeof(*item) > sizeof(freed_item_t)) ?\
51 sizeof(*item) : sizeof(freed_item_t));\
55 list=(void *)(((freed_item_t *)((void *)item))->next);
57 #define SLAB_FREE(item, list) \
59 ((freed_item_t *)((void *)item))->next= \
60 (freed_item_t *)((void *)list); \