se_alloc not ep_alloc!
[metze/wireshark/wip.git] / epan / emem.h
1 /* emem.h
2  * Definitions for ethereal memory management and garbage collection
3  * Ronnie Sahlberg 2005
4  *
5  * $Id$
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifndef __EMEM_H__
27 #define __EMEM_H__
28
29 /* Functions for handling memory allocation and garbage collection with 
30  * a packet lifetime scope.
31  * These functions are used to allocate memory that will only remain persistent
32  * until ethereal starts dissecting the next packet in the list.
33  * Everytime ethereal starts decoding the next packet all memory allocated
34  * through these functions will be released back to the free pool.
35  *
36  * These functions are very fast and offer automatic garbage collection:
37  * Everytime a new packet is dissected, all memory allocations done in
38  * the previous packet is freed.
39  */
40 /* Initialize packet-lifetime memory allocation pool. This function is called 
41  * once when [t]ethereal is initialized to set up the required structures.
42  */
43 void ep_init_chunk(void);
44
45 /* Allocate memory with a packet lifetime scope */
46 void *ep_alloc(size_t size);
47
48 /* Allocate memory with a packet lifetime scope and fill it with zeros*/
49 void* ep_alloc0(size_t size);
50
51 /* Duplicate a string with a packet lifetime scope */
52 gchar* ep_strdup(const gchar* src);
53
54 /* Duplicate at most n characters of a string with a packet lifetime scope */
55 gchar* ep_strndup(const gchar* src, size_t len);
56
57 /* Duplicate a buffer with a packet lifetime scope */
58 guint8* ep_memdup(const guint8* src, size_t len);
59
60 /* Create a formated string with a packet lifetime scope */
61 gchar* ep_strdup_printf(const gchar* fmt, ...);
62
63 /* allocates with a packet lifetime scope an array of type made of num elements */
64 #define ep_alloc_array(type,num) (type*)ep_alloc(sizeof(type)*(num))
65
66 /* 
67  * Splits a string into a maximum of max_tokens pieces, using the given
68  * delimiter. If max_tokens is reached, the remainder of string is appended
69  * to the last token. Consecutive delimiters are treated as a single delimiter.
70  *
71  * the vector and all the strings are allocated with packet lifetime scope
72  */
73 gchar** ep_strsplit(const gchar* string, const gchar* delimiter, int max_tokens);
74
75 /* release all memory allocated in the previous packet dissector */
76 void ep_free_all(void);
77
78
79
80
81
82 /* Functions for handling memory allocation and garbage collection with 
83  * a capture lifetime scope.
84  * These functions are used to allocate memory that will only remain persistent
85  * until ethereal opens a new capture or capture file.
86  * Everytime ethereal starts a new capture or opens a new capture file
87  * all the data allocated through these functions will be released back 
88  * to the free pool.
89  *
90  * These functions are very fast and offer automatic garbage collection.
91  */
92 /* Initialize capture-lifetime memory allocation pool. This function is called 
93  * once when [t]ethereal is initialized to set up the required structures.
94  */
95 void se_init_chunk(void);
96
97 /* Allocate memory with a capture lifetime scope */
98 void *se_alloc(size_t size);
99
100 /* Allocate memory with a capture lifetime scope and fill it with zeros*/
101 void* se_alloc0(size_t size);
102
103 /* Duplicate a string with a capture lifetime scope */
104 gchar* se_strdup(const gchar* src);
105
106 /* Duplicate at most n characters of a string with a capture lifetime scope */
107 gchar* se_strndup(const gchar* src, size_t len);
108
109 /* Duplicate a buffer with a capture lifetime scope */
110 guint8* se_memdup(const guint8* src, size_t len);
111
112 /* Create a formated string with a capture lifetime scope */
113 gchar* se_strdup_printf(const gchar* fmt, ...);
114
115 /* allocates with a capture lifetime scope an array of type made of num elements */
116 #define se_alloc_array(type,num) (type*)se_alloc(sizeof(type)*(num))
117
118 /* release all memory allocated */
119 void se_free_all(void);
120
121
122 #endif /* emem.h */