/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
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
111
112
113
114
115
#ifndef __H_MM__
#define __H_MM__

#include "defs.h"

#if USE_GC
#include <gc/gc.h>
#endif

S_BEGIN_DECLS

/**
 * @defgroup MemoryM Memory Management
 * @addtogroup MemoryM
 * @{
 * @brief Memory management stuff.
 *
 * By default libssts does not use a GC, it can be enabled with by setting the
 * USE_GC switch in cmake.
 *
 * Even if you have GC enabled, it is important to make sure that when you do
 * not use the GC it will still cleanup all the pointers.
 *
 * General rule: for every @ref s_malloc() have a @ref s_free() even if you know
 * you are running a GC.
 */

/**
 * Represents what sort of memory management should be used. Used by
 * @ref s_mm_init.
 */
typedef enum {
  S_MM_TYPE_NONE,
  S_MM_TYPE_LIBC,
  S_MM_TYPE_GC
} SMMType;

/**
 * The names of for the enum @ref SMMType.
 */
S_UNUSED static
schar * SMMTypeName[] = {
  "NONE",
  "libc",
  "GC",
  0x0,
  0x0
};

/**
 * Get the name of SMMType.
 *
 * For used in bindings.
 */
schar *
s_mm_type_get_name (SMMType type);

/**
 * Set how memory should be dealth with.
 *
 * Only has effect if you compile with GC enabled.
 */
void
s_mm_init (SMMType type);

/**
 * Clean up memory management.
 * Does nothing.
 */
void
s_mm_cleanup ();

/**
 * Get what sort of memory management is used.
 */
SMMType
s_mm_get_type ();

/**
 * By default this is this is just a normal call to malloc. But with
 * GC enabled it will use GC_MALLOC to allocate memory.
 */
spointer
s_malloc (size_t size);

/**
 * by default this acts just as a normal call to free. If GC is enabled this
 * will set the pointer to NULL.
 */
void
s_free (spointer pointer);

/**
 * By default this will act just as a normal call to realloc. But if GC is
 * enabled this will use GC_REALLOC.
 */
spointer
s_realloc (spointer pointer, size_t size);

/**
 * By default this acts as a normal call to calloc. If GC in enabled this
 * will just wrap GC_MALLOC, as there is no GC_CALLOC.
 */
spointer
s_calloc (size_t num, size_t size);

/** @} */

/**
 * @}
 */

S_END_DECLS

#endif /* __H_MM__ */