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. svn path=/trunk/; revision=9150
This commit is contained in:
parent
e4b6c50461
commit
ed2ae2d8d3
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: ftypes.c,v 1.16 2003/12/02 21:15:48 guy Exp $
|
||||
* $Id: ftypes.c,v 1.17 2003/12/03 08:53:37 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -193,7 +193,7 @@ fvalue_new(ftenum_t ftype)
|
|||
ftype_t *ft;
|
||||
FvalueNewFunc new_value;
|
||||
|
||||
SLAB_ALLOC(fv, fv->ptr_u.next, fvalue_free_list);
|
||||
SLAB_ALLOC(fv, fvalue_free_list);
|
||||
|
||||
FTYPE_LOOKUP(ftype, ft);
|
||||
fv->ptr_u.ftype = ft;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* ftypes.h
|
||||
* Definitions for field types
|
||||
*
|
||||
* $Id: ftypes.h,v 1.23 2003/12/02 21:15:48 guy Exp $
|
||||
* $Id: ftypes.h,v 1.24 2003/12/03 08:53:37 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -128,7 +128,6 @@ ftype_can_contains(enum ftenum ftype);
|
|||
|
||||
typedef struct _fvalue_t {
|
||||
union {
|
||||
struct _fvalue_t *next;
|
||||
ftype_t *ftype;
|
||||
} ptr_u;
|
||||
union {
|
||||
|
@ -226,7 +225,7 @@ extern fvalue_t *fvalue_free_list;
|
|||
#define FVALUE_FREE(fv) \
|
||||
{ \
|
||||
FVALUE_CLEANUP(fv) \
|
||||
SLAB_FREE(fv, fv->ptr_u.next, fvalue_free_list);\
|
||||
SLAB_FREE(fv, fvalue_free_list); \
|
||||
}
|
||||
|
||||
|
||||
|
|
14
epan/proto.c
14
epan/proto.c
|
@ -1,7 +1,7 @@
|
|||
/* proto.c
|
||||
* Routines for protocol tree
|
||||
*
|
||||
* $Id: proto.c,v 1.120 2003/12/02 21:15:47 guy Exp $
|
||||
* $Id: proto.c,v 1.121 2003/12/03 08:53:36 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -156,27 +156,27 @@ static GMemChunk *gmc_hfinfo = NULL;
|
|||
static field_info *field_info_free_list=NULL;
|
||||
static field_info *field_info_tmp=NULL;
|
||||
#define FIELD_INFO_NEW(fi) \
|
||||
SLAB_ALLOC(fi, fi->ptr_u.next, field_info_free_list)
|
||||
SLAB_ALLOC(fi, field_info_free_list)
|
||||
#define FIELD_INFO_FREE(fi) \
|
||||
SLAB_FREE(fi, fi->ptr_u.next, field_info_free_list)
|
||||
SLAB_FREE(fi, field_info_free_list)
|
||||
|
||||
|
||||
|
||||
/* Contains the space for proto_nodes. */
|
||||
static proto_node *proto_node_free_list=NULL;
|
||||
#define PROTO_NODE_NEW(node) \
|
||||
SLAB_ALLOC(node, node->next, proto_node_free_list)
|
||||
SLAB_ALLOC(node, proto_node_free_list)
|
||||
#define PROTO_NODE_FREE(node) \
|
||||
SLAB_FREE(node, node->next, proto_node_free_list)
|
||||
SLAB_FREE(node, proto_node_free_list)
|
||||
|
||||
|
||||
|
||||
/* String space for protocol and field items for the GUI */
|
||||
static item_label_t *item_label_free_list = NULL;
|
||||
#define ITEM_LABEL_NEW(il) \
|
||||
SLAB_ALLOC(il, il->next, item_label_free_list)
|
||||
SLAB_ALLOC(il, item_label_free_list)
|
||||
#define ITEM_LABEL_FREE(il) \
|
||||
SLAB_FREE(il, il->next, item_label_free_list)
|
||||
SLAB_FREE(il, item_label_free_list)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* proto.h
|
||||
* Definitions for protocol display
|
||||
*
|
||||
* $Id: proto.h,v 1.49 2003/12/02 21:15:47 guy Exp $
|
||||
* $Id: proto.h,v 1.50 2003/12/03 08:53:36 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -104,7 +104,6 @@ typedef struct hf_register_info {
|
|||
|
||||
|
||||
typedef struct _item_label_t {
|
||||
struct _item_label_t *next;
|
||||
char representation[ITEM_LABEL_LENGTH];
|
||||
} item_label_t;
|
||||
|
||||
|
@ -137,7 +136,6 @@ typedef struct {
|
|||
/* Each GNode (proto_tree, proto_item) points to one of
|
||||
* these. */
|
||||
typedef struct _proto_node {
|
||||
struct _proto_node *next;
|
||||
field_info *finfo;
|
||||
tree_data_t *tree_data;
|
||||
} proto_node;
|
||||
|
|
38
epan/slab.h
38
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 */
|
||||
|
|
Loading…
Reference in New Issue