gfsmMem.h
Go to the documentation of this file.
1 
2 /*=============================================================================*\
3  * File: gfsmMem.h
4  * Author: Bryan Jurish <moocow.bovine@gmail.com>
5  * Description: finite state machine library: memory utilities (currently unused)
6  *
7  * Copyright (c) 2004-2011 Bryan Jurish.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  *=============================================================================*/
23 
28 #ifndef _GFSM_MEM_H
29 #define _GFSM_MEM_H
30 
31 #include <glib.h>
32 #include <gfsmConfig.h>
33 
34 //======================================================================
36 
37 /* - these aren't used by default!
38  * - for gfsm2.10 they shouldn't be used at all
39  */
40 
41 //-- new for v0.0.10 : chuck deprecated GAllocator
42 #ifdef GFSM_USE_GALLOCATOR
43 
45 extern GAllocator *gfsm_node_allocator;
46 
48 extern GAllocator *gfsm_slist_allocator;
49 
51 extern GAllocator *gfsm_list_allocator;
52 
54 extern gboolean gfsm_allocators_enabled;
55 
58 void gfsm_allocators_init(void);
59 
62 void gfsm_allocators_enable(void);
63 
66 void gfsm_allocators_disable(void);
67 
70 void gfsm_allocators_free(void);
71 
72 #endif /* GFSM_USE_GALLOCATOR */
73 
74 //======================================================================
76 
77 
80 gpointer gfsm_slice_alloc(guint block_size);
81 
84 gpointer gfsm_slice_alloc0(guint block_size);
85 
88 gpointer gfsm_slice_copy(guint block_size, gconstpointer src);
89 
92 void gfsm_slice_free1(gsize block_size, gpointer mem_block);
93 
95 #ifdef GFSM_USE_GSLICE
96 # define gfsm_slice_new(type) g_slice_new(type)
97 #else
98 # define gfsm_slice_new(type) g_new(type,1)
99 #endif
100 
102 #ifdef GFSM_USE_GSLICE
103 # define gfsm_slice_new_n(type,n) (type*)g_slice_alloc(sizeof(type)*(n))
104 #else
105 # define gfsm_slice_new_n(type,n) (type*)g_malloc(sizeof(type)*(n))
106 #endif
107 
109 #ifdef GFSM_USE_GSLICE
110 # define gfsm_slice_new0(type) g_slice_new0(type)
111 #else
112 # define gfsm_slice_new0(type) g_new0(type,1)
113 #endif
114 
116 #ifdef GFSM_USE_GSLICE
117 # define gfsm_slice_new0_n(type,n) (type*)g_slice_alloc0(sizeof(type)*(n))
118 #else
119 # define gfsm_slice_new0_n(type,n) (type*)g_malloc0(sizeof(type)*(n))
120 #endif
121 
123 #ifdef GFSM_USE_GSLICE
124 # define gfsm_slice_dup(type,mem) g_slice_dup(type,(mem))
125 #else
126 # define gfsm_slice_dup(type,mem) g_memdup((mem),sizeof(type))
127 #endif
128 
130 #ifdef GFSM_USE_GSLICE
131 # define gfsm_slice_free(type,mem) g_slice_free(type,(type*)(mem))
132 #else
133 # define gfsm_slice_free(type,mem) g_free((mem))
134 #endif
135 
137 #ifdef GFSM_USE_GSLICE
138 # define gfsm_slice_free_n(type,mem,n) g_slice_free1(sizeof(type)*(n),(gpointer)(mem))
139 #else
140 # define gfsm_slice_free_n(type,mem,n) g_free((gpointer)(mem))
141 #endif
142 
144 
145 //======================================================================
147 
148 
150 typedef gpointer (*gfsmDupNFunc) (gconstpointer src, gsize size);
151 
153 typedef gpointer (*gfsmDupFunc) (gconstpointer src);
154 
156 #define gfsm_new(struct_type, n_structs) g_new(struct_type, (n_structs))
157 
159 #define gfsm_new0(struct_type, n_structs) g_new0(struct_type, (n_structs))
160 
163 void gfsm_free(gpointer mem);
164 
167 gpointer gfsm_string_dup_n (gconstpointer src, gsize size);
168 
171 gpointer gfsm_mem_dup_n (gconstpointer src, gsize size);
172 
174 #define gfsm_string_dup g_strdup
175 
178 GString *gfsm_gstring_dup (GString *gstr);
179 
182 void gfsm_gstring_assign_bytes (GString *gstr, const gchar *src, gsize len);
183 
186 GString *gfsm_gstring_new_bytes (const gchar *src, gsize len);
187 
189 
190 //-- inline definitions
191 #ifdef GFSM_INLINE_ENABLED
192 # include <gfsmMem.hi>
193 #endif
194 
195 #endif /* _GFSM_MEM_H */