alternative to assert
[gtkD.git] / gtkD / src / glib / Memory.d
blob84e0aed8c9c0a9967b8bc723ae28612521b36804
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Memory-Allocation.html
26 * outPack = glib
27 * outFile = Memory
28 * strct =
29 * realStrct=
30 * ctorStrct=
31 * clss = Memory
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * structWrap:
45 * module aliases:
46 * local aliases:
49 module glib.Memory;
51 version(noAssert)
53 version(Tango)
55 import tango.io.Stdout; // use the tango loging?
59 private import gtkc.glibtypes;
61 private import gtkc.glib;
68 /**
69 * Description
70 * These functions provide support for allocating and freeing memory.
71 * Note
72 * If any call to allocate memory fails, the application is terminated.
73 * This also means that there is no need to check if the call succeeded.
75 public class Memory
78 /**
87 /**
88 * Allocates n_bytes bytes of memory.
89 * If n_bytes is 0 it returns NULL.
90 * n_bytes:
91 * the number of bytes to allocate.
92 * Returns:
93 * a pointer to the allocated memory.
95 public static void* malloc(uint nBytes)
97 // gpointer g_malloc (gulong n_bytes);
98 return g_malloc(nBytes);
102 * Allocates n_bytes bytes of memory, initialized to 0's.
103 * If n_bytes is 0 it returns NULL.
104 * n_bytes:
105 * the number of bytes to allocate.
106 * Returns:
107 * a pointer to the allocated memory.
109 public static void* malloc0(uint nBytes)
111 // gpointer g_malloc0 (gulong n_bytes);
112 return g_malloc0(nBytes);
116 * Reallocates the memory pointed to by mem, so that it now has space for
117 * n_bytes bytes of memory. It returns the new address of the memory, which may
118 * have been moved. mem may be NULL, in which case it's considered to
119 * have zero-length. n_bytes may be 0, in which case NULL will be returned.
120 * mem:
121 * the memory to reallocate.
122 * n_bytes:
123 * new size of the memory in bytes.
124 * Returns:
125 * the new address of the allocated memory.
127 public static void* realloc(void* mem, uint nBytes)
129 // gpointer g_realloc (gpointer mem, gulong n_bytes);
130 return g_realloc(mem, nBytes);
134 * Attempts to allocate n_bytes, and returns NULL on failure.
135 * Contrast with g_malloc(), which aborts the program on failure.
136 * n_bytes:
137 * number of bytes to allocate.
138 * Returns:
139 * the allocated memory, or NULL.
141 public static void* tryMalloc(uint nBytes)
143 // gpointer g_try_malloc (gulong n_bytes);
144 return g_try_malloc(nBytes);
148 * Attempts to allocate n_bytes, initialized to 0's, and returns NULL on
149 * failure. Contrast with g_malloc0(), which aborts the program on failure.
150 * n_bytes:
151 * number of bytes to allocate.
152 * Returns:
153 * the allocated memory, or NULL.
154 * Since 2.8
156 public static void* tryMalloc0(uint nBytes)
158 // gpointer g_try_malloc0 (gulong n_bytes);
159 return g_try_malloc0(nBytes);
163 * Attempts to realloc mem to a new size, n_bytes, and returns NULL
164 * on failure. Contrast with g_realloc(), which aborts the program
165 * on failure. If mem is NULL, behaves the same as g_try_malloc().
166 * mem:
167 * previously-allocated memory, or NULL.
168 * n_bytes:
169 * number of bytes to allocate.
170 * Returns:
171 * the allocated memory, or NULL.
173 public static void* tryRealloc(void* mem, uint nBytes)
175 // gpointer g_try_realloc (gpointer mem, gulong n_bytes);
176 return g_try_realloc(mem, nBytes);
180 * Frees the memory pointed to by mem.
181 * If mem is NULL it simply returns.
182 * mem:
183 * the memory to free.
185 public static void free(void* mem)
187 // void g_free (gpointer mem);
188 g_free(mem);
196 * Allocates byte_size bytes of memory, and copies byte_size bytes into it
197 * from mem. If mem is NULL it returns NULL.
198 * mem:
199 * the memory to copy.
200 * byte_size:
201 * the number of bytes to copy.
202 * Returns:
203 * a pointer to the newly-allocated copy of the memory, or NULL if mem
204 * is NULL.
206 public static void* memdup(void* mem, uint byteSize)
208 // gpointer g_memdup (gconstpointer mem, guint byte_size);
209 return g_memdup(mem, byteSize);
214 * Sets the GMemVTable to use for memory allocation. You can use this to provide
215 * custom memory allocation routines. This function must be called before using any other GLib functions. The vtable only needs to provide malloc(), realloc(), and free()
216 * functions; GLib can provide default implementations of the others. The malloc()
217 * and realloc() implementations should return NULL on failure, GLib will handle
218 * error-checking for you. vtable is copied, so need not persist after this
219 * function has been called.
220 * vtable:
221 * table of memory allocation routines.
223 public static void memSetVtable(GMemVTable* vtable)
225 // void g_mem_set_vtable (GMemVTable *vtable);
226 g_mem_set_vtable(vtable);
230 * Checks whether the allocator used by g_malloc() is the system's
231 * malloc implementation. If it returns TRUE memory allocated with
232 * malloc() can be used interchangeable with memory allocated using g_malloc().
233 * This function is useful for avoiding an extra copy of allocated memory returned
234 * by a non-GLib-based API.
235 * A different allocator can be set using g_mem_set_vtable().
236 * Returns:
237 * if TRUE, malloc() and g_malloc() can be mixed.
239 public static int memIsSystemMalloc()
241 // gboolean g_mem_is_system_malloc (void);
242 return g_mem_is_system_malloc();
247 * Outputs a summary of memory usage.
248 * It outputs the frequency of allocations of different sizes,
249 * the total number of bytes which have been allocated,
250 * the total number of bytes which have been freed,
251 * and the difference between the previous two values, i.e. the number of bytes
252 * still in use.
253 * Note that this function will not output anything unless you have
254 * previously installed the glib_mem_profiler_table with g_mem_set_vtable().
256 public static void memProfile()
258 // void g_mem_profile (void);
259 g_mem_profile();