2 * Definitions for ethereal memory management and garbage collection
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
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.
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.
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.
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.
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.
40 /* Initialize packet-lifetime memory allocation pool. This function is called
41 * once when [t]ethereal is initialized to set up the required structures.
43 void ep_init_chunk(void);
45 /* Allocate memory with a packet lifetime scope */
46 void *ep_alloc(size_t size);
48 /* Allocate memory with a packet lifetime scope and fill it with zeros*/
49 void* ep_alloc0(size_t size);
51 /* Duplicate a string with a packet lifetime scope */
52 gchar* ep_strdup(const gchar* src);
54 /* Duplicate at most n characters of a string with a packet lifetime scope */
55 gchar* ep_strndup(const gchar* src, size_t len);
57 /* Duplicate a buffer with a packet lifetime scope */
58 guint8* ep_memdup(const guint8* src, size_t len);
60 /* Create a formated string with a packet lifetime scope */
61 gchar* ep_strdup_printf(const gchar* fmt, ...);
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))
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.
71 * the vector and all the strings are allocated with packet lifetime scope
73 gchar** ep_strsplit(const gchar* string, const gchar* delimiter, int max_tokens);
75 /* release all memory allocated in the previous packet dissector */
76 void ep_free_all(void);
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
90 * These functions are very fast and offer automatic garbage collection.
92 /* Initialize capture-lifetime memory allocation pool. This function is called
93 * once when [t]ethereal is initialized to set up the required structures.
95 void se_init_chunk(void);
97 /* Allocate memory with a capture lifetime scope */
98 void *se_alloc(size_t size);
100 /* Allocate memory with a capture lifetime scope and fill it with zeros*/
101 void* se_alloc0(size_t size);
103 /* Duplicate a string with a capture lifetime scope */
104 gchar* se_strdup(const gchar* src);
106 /* Duplicate at most n characters of a string with a capture lifetime scope */
107 gchar* se_strndup(const gchar* src, size_t len);
109 /* Duplicate a buffer with a capture lifetime scope */
110 guint8* se_memdup(const guint8* src, size_t len);
112 /* Create a formated string with a capture lifetime scope */
113 gchar* se_strdup_printf(const gchar* fmt, ...);
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))
118 /* release all memory allocated */
119 void se_free_all(void);