aboutsummaryrefslogtreecommitdiff
path: root/gfsm/gfsm/src/libgfsm/gfsmMem.h
blob: 4791d26cbafde2ffda3c5ea934bf526545acea99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

/*=============================================================================*\
 * File: gfsmMem.h
 * Author: Bryan Jurish <moocow@ling.uni-potsdam.de>
 * Description: finite state machine library: memory utilities (currently unused)
 *
 * Copyright (c) 2004 Bryan Jurish.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *=============================================================================*/

/** \file gfsmMem.h
 *  \brief Memory utilities
 */

#ifndef _GFSM_MEM_H
#define _GFSM_MEM_H

#include <glib.h>
#include <gfsmConfig.h>

/*----------------------------------------------------------------------
 * Allocators: variables
 */

/** Default GNode allocator */
extern GAllocator *gfsm_node_allocator;

/** Default GSList allocator */
extern GAllocator *gfsm_slist_allocator;

/** Default GList allocator */
extern GAllocator *gfsm_list_allocator;

/** Whether gfsm allocators are currently enabled */
extern gboolean gfsm_allocators_enabled;


/*----------------------------------------------------------------------
 * Allocators
 *  - these aren't used by default!
 */

/** Ensure that gfsm allocators are defined and non-NULL */
GFSM_INLINE
void gfsm_allocators_init(void);

/** Push gfsm allocators to the stack */
GFSM_INLINE
void gfsm_allocators_enable(void);

/** Pop gfsm allocators from the stack */
GFSM_INLINE
void gfsm_allocators_disable(void);

/** Free all memory allocated by the gfsm allocators */
GFSM_INLINE
void gfsm_allocators_free(void);


/*----------------------------------------------------------------------
 * Copying
 */
/** Abstract copy function */
typedef gpointer    (*gfsmDupNFunc)    (gconstpointer src, gsize size);

/** Abstract duplication function */
typedef gpointer    (*gfsmDupFunc)     (gconstpointer src);

/** String copy function for NUL-terminated strings */
GFSM_INLINE
gpointer gfsm_string_dup_n (gconstpointer src, gsize size);

/** size-based copy function */
GFSM_INLINE
gpointer gfsm_mem_dup_n (gconstpointer src, gsize size);

/** String duplication function for NUL-terminated strings */
#define gfsm_string_dup g_strdup

/** String duplication function for GString*s */
GFSM_INLINE
GString *gfsm_gstring_dup (GString *gstr);

/** Byte-assignment for GString*s */
GFSM_INLINE
void gfsm_gstring_assign_bytes (GString *gstr, const gchar *src, gsize len);

/** Byte-vector creation for GString*s */
GFSM_INLINE
GString *gfsm_gstring_new_bytes (const gchar *src, gsize len);

//-- inline definitions
#ifdef GFSM_INLINE_ENABLED
# include <gfsmMem.hi>
#endif

#endif /* _GFSM_MEM_H */