1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.Memory;
26 
27 private import glib.c.functions;
28 public  import glib.c.types;
29 public  import gtkc.glibtypes;
30 
31 
32 /** */
33 public struct Memory
34 {
35 
36 	/**
37 	 * Clears a reference to a variable.
38 	 *
39 	 * @pp must not be %NULL.
40 	 *
41 	 * If the reference is %NULL then this function does nothing.
42 	 * Otherwise, the variable is destroyed using @destroy and the
43 	 * pointer is set to %NULL.
44 	 *
45 	 * A macro is also included that allows this function to be used without
46 	 * pointer casts.
47 	 *
48 	 * Params:
49 	 *     pp = a pointer to a variable, struct member etc. holding a
50 	 *         pointer
51 	 *     destroy = a function to which a gpointer can be passed, to destroy *@pp
52 	 *
53 	 * Since: 2.34
54 	 */
55 	public static void clearPointer(void** pp, GDestroyNotify destroy)
56 	{
57 		g_clear_pointer(pp, destroy);
58 	}
59 
60 	/**
61 	 * Frees the memory pointed to by @mem.
62 	 *
63 	 * If @mem is %NULL it simply returns, so there is no need to check @mem
64 	 * against %NULL before calling this function.
65 	 *
66 	 * Params:
67 	 *     mem = the memory to free
68 	 */
69 	public static void free(void* mem)
70 	{
71 		g_free(mem);
72 	}
73 
74 	/**
75 	 * Allocates @n_bytes bytes of memory.
76 	 * If @n_bytes is 0 it returns %NULL.
77 	 *
78 	 * Params:
79 	 *     nBytes = the number of bytes to allocate
80 	 *
81 	 * Returns: a pointer to the allocated memory
82 	 */
83 	public static void* malloc(size_t nBytes)
84 	{
85 		return g_malloc(nBytes);
86 	}
87 
88 	/**
89 	 * Allocates @n_bytes bytes of memory, initialized to 0's.
90 	 * If @n_bytes is 0 it returns %NULL.
91 	 *
92 	 * Params:
93 	 *     nBytes = the number of bytes to allocate
94 	 *
95 	 * Returns: a pointer to the allocated memory
96 	 */
97 	public static void* malloc0(size_t nBytes)
98 	{
99 		return g_malloc0(nBytes);
100 	}
101 
102 	/**
103 	 * This function is similar to g_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
104 	 * but care is taken to detect possible overflow during multiplication.
105 	 *
106 	 * Params:
107 	 *     nBlocks = the number of blocks to allocate
108 	 *     nBlockBytes = the size of each block in bytes
109 	 *
110 	 * Returns: a pointer to the allocated memory
111 	 *
112 	 * Since: 2.24
113 	 */
114 	public static void* malloc0N(size_t nBlocks, size_t nBlockBytes)
115 	{
116 		return g_malloc0_n(nBlocks, nBlockBytes);
117 	}
118 
119 	/**
120 	 * This function is similar to g_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
121 	 * but care is taken to detect possible overflow during multiplication.
122 	 *
123 	 * Params:
124 	 *     nBlocks = the number of blocks to allocate
125 	 *     nBlockBytes = the size of each block in bytes
126 	 *
127 	 * Returns: a pointer to the allocated memory
128 	 *
129 	 * Since: 2.24
130 	 */
131 	public static void* mallocN(size_t nBlocks, size_t nBlockBytes)
132 	{
133 		return g_malloc_n(nBlocks, nBlockBytes);
134 	}
135 
136 	/**
137 	 * Checks whether the allocator used by g_malloc() is the system's
138 	 * malloc implementation. If it returns %TRUE memory allocated with
139 	 * malloc() can be used interchangeable with memory allocated using g_malloc().
140 	 * This function is useful for avoiding an extra copy of allocated memory returned
141 	 * by a non-GLib-based API.
142 	 *
143 	 * Deprecated: GLib always uses the system malloc, so this function always
144 	 * returns %TRUE.
145 	 *
146 	 * Returns: if %TRUE, malloc() and g_malloc() can be mixed.
147 	 */
148 	public static bool memIsSystemMalloc()
149 	{
150 		return g_mem_is_system_malloc() != 0;
151 	}
152 
153 	/**
154 	 * GLib used to support some tools for memory profiling, but this
155 	 * no longer works. There are many other useful tools for memory
156 	 * profiling these days which can be used instead.
157 	 *
158 	 * Deprecated: Use other memory profiling tools instead
159 	 */
160 	public static void memProfile()
161 	{
162 		g_mem_profile();
163 	}
164 
165 	/**
166 	 * This function used to let you override the memory allocation function.
167 	 * However, its use was incompatible with the use of global constructors
168 	 * in GLib and GIO, because those use the GLib allocators before main is
169 	 * reached. Therefore this function is now deprecated and is just a stub.
170 	 *
171 	 * Deprecated: This function now does nothing. Use other memory
172 	 * profiling tools instead
173 	 *
174 	 * Params:
175 	 *     vtable = table of memory allocation routines.
176 	 */
177 	public static void memSetVtable(GMemVTable* vtable)
178 	{
179 		g_mem_set_vtable(vtable);
180 	}
181 
182 	/**
183 	 * Allocates @byte_size bytes of memory, and copies @byte_size bytes into it
184 	 * from @mem. If @mem is %NULL it returns %NULL.
185 	 *
186 	 * Params:
187 	 *     mem = the memory to copy.
188 	 *     byteSize = the number of bytes to copy.
189 	 *
190 	 * Returns: a pointer to the newly-allocated copy of the memory, or %NULL if @mem
191 	 *     is %NULL.
192 	 */
193 	public static void* memdup(void* mem, uint byteSize)
194 	{
195 		return g_memdup(mem, byteSize);
196 	}
197 
198 	/**
199 	 * Reallocates the memory pointed to by @mem, so that it now has space for
200 	 * @n_bytes bytes of memory. It returns the new address of the memory, which may
201 	 * have been moved. @mem may be %NULL, in which case it's considered to
202 	 * have zero-length. @n_bytes may be 0, in which case %NULL will be returned
203 	 * and @mem will be freed unless it is %NULL.
204 	 *
205 	 * Params:
206 	 *     mem = the memory to reallocate
207 	 *     nBytes = new size of the memory in bytes
208 	 *
209 	 * Returns: the new address of the allocated memory
210 	 */
211 	public static void* realloc(void* mem, size_t nBytes)
212 	{
213 		return g_realloc(mem, nBytes);
214 	}
215 
216 	/**
217 	 * This function is similar to g_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
218 	 * but care is taken to detect possible overflow during multiplication.
219 	 *
220 	 * Params:
221 	 *     mem = the memory to reallocate
222 	 *     nBlocks = the number of blocks to allocate
223 	 *     nBlockBytes = the size of each block in bytes
224 	 *
225 	 * Returns: the new address of the allocated memory
226 	 *
227 	 * Since: 2.24
228 	 */
229 	public static void* reallocN(void* mem, size_t nBlocks, size_t nBlockBytes)
230 	{
231 		return g_realloc_n(mem, nBlocks, nBlockBytes);
232 	}
233 
234 	/**
235 	 * Attempts to allocate @n_bytes, and returns %NULL on failure.
236 	 * Contrast with g_malloc(), which aborts the program on failure.
237 	 *
238 	 * Params:
239 	 *     nBytes = number of bytes to allocate.
240 	 *
241 	 * Returns: the allocated memory, or %NULL.
242 	 */
243 	public static void* tryMalloc(size_t nBytes)
244 	{
245 		return g_try_malloc(nBytes);
246 	}
247 
248 	/**
249 	 * Attempts to allocate @n_bytes, initialized to 0's, and returns %NULL on
250 	 * failure. Contrast with g_malloc0(), which aborts the program on failure.
251 	 *
252 	 * Params:
253 	 *     nBytes = number of bytes to allocate
254 	 *
255 	 * Returns: the allocated memory, or %NULL
256 	 *
257 	 * Since: 2.8
258 	 */
259 	public static void* tryMalloc0(size_t nBytes)
260 	{
261 		return g_try_malloc0(nBytes);
262 	}
263 
264 	/**
265 	 * This function is similar to g_try_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
266 	 * but care is taken to detect possible overflow during multiplication.
267 	 *
268 	 * Params:
269 	 *     nBlocks = the number of blocks to allocate
270 	 *     nBlockBytes = the size of each block in bytes
271 	 *
272 	 * Returns: the allocated memory, or %NULL
273 	 *
274 	 * Since: 2.24
275 	 */
276 	public static void* tryMalloc0N(size_t nBlocks, size_t nBlockBytes)
277 	{
278 		return g_try_malloc0_n(nBlocks, nBlockBytes);
279 	}
280 
281 	/**
282 	 * This function is similar to g_try_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
283 	 * but care is taken to detect possible overflow during multiplication.
284 	 *
285 	 * Params:
286 	 *     nBlocks = the number of blocks to allocate
287 	 *     nBlockBytes = the size of each block in bytes
288 	 *
289 	 * Returns: the allocated memory, or %NULL.
290 	 *
291 	 * Since: 2.24
292 	 */
293 	public static void* tryMallocN(size_t nBlocks, size_t nBlockBytes)
294 	{
295 		return g_try_malloc_n(nBlocks, nBlockBytes);
296 	}
297 
298 	/**
299 	 * Attempts to realloc @mem to a new size, @n_bytes, and returns %NULL
300 	 * on failure. Contrast with g_realloc(), which aborts the program
301 	 * on failure.
302 	 *
303 	 * If @mem is %NULL, behaves the same as g_try_malloc().
304 	 *
305 	 * Params:
306 	 *     mem = previously-allocated memory, or %NULL.
307 	 *     nBytes = number of bytes to allocate.
308 	 *
309 	 * Returns: the allocated memory, or %NULL.
310 	 */
311 	public static void* tryRealloc(void* mem, size_t nBytes)
312 	{
313 		return g_try_realloc(mem, nBytes);
314 	}
315 
316 	/**
317 	 * This function is similar to g_try_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
318 	 * but care is taken to detect possible overflow during multiplication.
319 	 *
320 	 * Params:
321 	 *     mem = previously-allocated memory, or %NULL.
322 	 *     nBlocks = the number of blocks to allocate
323 	 *     nBlockBytes = the size of each block in bytes
324 	 *
325 	 * Returns: the allocated memory, or %NULL.
326 	 *
327 	 * Since: 2.24
328 	 */
329 	public static void* tryReallocN(void* mem, size_t nBlocks, size_t nBlockBytes)
330 	{
331 		return g_try_realloc_n(mem, nBlocks, nBlockBytes);
332 	}
333 }