diff options
author | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2003-12-03 08:53:37 +0000 |
---|---|---|
committer | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2003-12-03 08:53:37 +0000 |
commit | 4eebf4000393b53ab460b1c209993853f11d9bc9 (patch) | |
tree | bc3e86e9db9fbe92dba89286b43c85a60383dfad /epan/slab.h | |
parent | a947fe281d964affe7f501224f328a153c9d66a1 (diff) |
Instead of requiring slab-allocated structures to have a "next" pointer,
when adding them to the free list, cast the pointer to the structure to
a pointer to a "freed_item_t" which contains the "next" pointer.
This reduces the memory requirement for some of those structures, and
leaves us free to slab-allocate structures that have a "next" pointer
for other reasons.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@9150 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan/slab.h')
-rw-r--r-- | epan/slab.h | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/epan/slab.h b/epan/slab.h index ab973bf26a..41e6ab1e09 100644 --- a/epan/slab.h +++ b/epan/slab.h @@ -1,7 +1,7 @@ /* slab.h * Definitions for very simple slab handling * - * $Id: slab.h,v 1.1 2003/12/02 09:11:16 sahlberg Exp $ + * $Id: slab.h,v 1.2 2003/12/03 08:53:36 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -25,26 +25,40 @@ #ifndef __SLAB_H__ #define __SLAB_H__ +#define NITEMS_PER_SLAB 100 + +typedef struct _freed_item { + struct _freed_item *next; +} freed_item_t; + /* we never free any memory we have allocated, when it is returned to us we just store it in the free list until (hopefully) it gets used again */ -#define SLAB_ALLOC(item, next, list) \ +#define SLAB_ALLOC(item, list) \ if(!list){ \ int i; \ - void *tmp; \ - tmp=g_malloc(100*sizeof(*item)); \ - for(i=0;i<100;i++){ \ - item=tmp; \ - item=&item[i]; \ - next=list; \ + char *tmp; \ + tmp=(char *)g_malloc(NITEMS_PER_SLAB* \ + ((sizeof(*item) > sizeof(freed_item_t)) ? \ + sizeof(*item) : sizeof(freed_item_t))); \ + for(i=0;i<NITEMS_PER_SLAB;i++){ \ + item=(void *)tmp; \ + ((freed_item_t *)((void *)item))->next= \ + (freed_item_t *)((void *)list); \ list=item; \ + tmp+= \ + ((sizeof(*item) > sizeof(freed_item_t)) ?\ + sizeof(*item) : sizeof(freed_item_t));\ } \ } \ item=list; \ - list=next; + list=(void *)(((freed_item_t *)((void *)item))->next); -#define SLAB_FREE(item, next, list) \ - next=list; \ - list=item; +#define SLAB_FREE(item, list) \ +{ \ + ((freed_item_t *)((void *)item))->next= \ + (freed_item_t *)((void *)list); \ + list=item; \ +} #endif /* slab.h */ |