sensitivity of packet range options fine tuning:
[obnox/wireshark/wip.git] / epan / slab.h
1 /* slab.h
2  * Definitions for very simple slab handling
3  *
4  * $Id: slab.h,v 1.2 2003/12/03 08:53:36 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifndef __SLAB_H__
26 #define __SLAB_H__
27
28 #define NITEMS_PER_SLAB 100
29
30 typedef struct _freed_item {
31         struct _freed_item *next;
32 } freed_item_t;
33
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
36 */
37 #define SLAB_ALLOC(item, list)                                  \
38         if(!list){                                              \
39                 int i;                                          \
40                 char *tmp;                                      \
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++){                 \
45                         item=(void *)tmp;                       \
46                         ((freed_item_t *)((void *)item))->next= \
47                             (freed_item_t *)((void *)list);     \
48                         list=item;                              \
49                         tmp+=                                   \
50                             ((sizeof(*item) > sizeof(freed_item_t)) ?\
51                                 sizeof(*item) : sizeof(freed_item_t));\
52                 }                                               \
53         }                                                       \
54         item=list;                                              \
55         list=(void *)(((freed_item_t *)((void *)item))->next);
56
57 #define SLAB_FREE(item, list)                           \
58 {                                                       \
59         ((freed_item_t *)((void *)item))->next=         \
60             (freed_item_t *)((void *)list);             \
61         list=item;                                      \
62 }
63
64 #endif /* slab.h */