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 
30 
31 /** */
32 public struct Memory
33 {
34 
35 	/**
36 	 * Clears a reference to a variable.
37 	 *
38 	 * @pp must not be %NULL.
39 	 *
40 	 * If the reference is %NULL then this function does nothing.
41 	 * Otherwise, the variable is destroyed using @destroy and the
42 	 * pointer is set to %NULL.
43 	 *
44 	 * A macro is also included that allows this function to be used without
45 	 * pointer casts. This will mask any warnings about incompatible function types
46 	 * or calling conventions, so you must ensure that your @destroy function is
47 	 * compatible with being called as `GDestroyNotify` using the standard calling
48 	 * convention for the platform that GLib was compiled for; otherwise the program
49 	 * will experience undefined behaviour.
50 	 *
51 	 * Params:
52 	 *     pp = a pointer to a variable, struct member etc. holding a
53 	 *         pointer
54 	 *     destroy = a function to which a gpointer can be passed, to destroy *@pp
55 	 *
56 	 * Since: 2.34
57 	 */
58 	public static void clearPointer(void** pp, GDestroyNotify destroy)
59 	{
60 		g_clear_pointer(pp, destroy);
61 	}
62 
63 	/**
64 	 * Frees the memory pointed to by @mem.
65 	 *
66 	 * If @mem is %NULL it simply returns, so there is no need to check @mem
67 	 * against %NULL before calling this function.
68 	 *
69 	 * Params:
70 	 *     mem = the memory to free
71 	 */
72 	public static void free(void* mem)
73 	{
74 		g_free(mem);
75 	}
76 
77 	/**
78 	 * Allocates @n_bytes bytes of memory.
79 	 * If @n_bytes is 0 it returns %NULL.
80 	 *
81 	 * Params:
82 	 *     nBytes = the number of bytes to allocate
83 	 *
84 	 * Returns: a pointer to the allocated memory
85 	 */
86 	public static void* malloc(size_t nBytes)
87 	{
88 		return g_malloc(nBytes);
89 	}
90 
91 	/**
92 	 * Allocates @n_bytes bytes of memory, initialized to 0's.
93 	 * If @n_bytes is 0 it returns %NULL.
94 	 *
95 	 * Params:
96 	 *     nBytes = the number of bytes to allocate
97 	 *
98 	 * Returns: a pointer to the allocated memory
99 	 */
100 	public static void* malloc0(size_t nBytes)
101 	{
102 		return g_malloc0(nBytes);
103 	}
104 
105 	/**
106 	 * This function is similar to g_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
107 	 * but care is taken to detect possible overflow during multiplication.
108 	 *
109 	 * Params:
110 	 *     nBlocks = the number of blocks to allocate
111 	 *     nBlockBytes = the size of each block in bytes
112 	 *
113 	 * Returns: a pointer to the allocated memory
114 	 *
115 	 * Since: 2.24
116 	 */
117 	public static void* malloc0N(size_t nBlocks, size_t nBlockBytes)
118 	{
119 		return g_malloc0_n(nBlocks, nBlockBytes);
120 	}
121 
122 	/**
123 	 * This function is similar to g_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
124 	 * but care is taken to detect possible overflow during multiplication.
125 	 *
126 	 * Params:
127 	 *     nBlocks = the number of blocks to allocate
128 	 *     nBlockBytes = the size of each block in bytes
129 	 *
130 	 * Returns: a pointer to the allocated memory
131 	 *
132 	 * Since: 2.24
133 	 */
134 	public static void* mallocN(size_t nBlocks, size_t nBlockBytes)
135 	{
136 		return g_malloc_n(nBlocks, nBlockBytes);
137 	}
138 
139 	/**
140 	 * Checks whether the allocator used by g_malloc() is the system's
141 	 * malloc implementation. If it returns %TRUE memory allocated with
142 	 * malloc() can be used interchangeably with memory allocated using g_malloc().
143 	 * This function is useful for avoiding an extra copy of allocated memory returned
144 	 * by a non-GLib-based API.
145 	 *
146 	 * Deprecated: GLib always uses the system malloc, so this function always
147 	 * returns %TRUE.
148 	 *
149 	 * Returns: if %TRUE, malloc() and g_malloc() can be mixed.
150 	 */
151 	public static bool memIsSystemMalloc()
152 	{
153 		return g_mem_is_system_malloc() != 0;
154 	}
155 
156 	/**
157 	 * GLib used to support some tools for memory profiling, but this
158 	 * no longer works. There are many other useful tools for memory
159 	 * profiling these days which can be used instead.
160 	 *
161 	 * Deprecated: Use other memory profiling tools instead
162 	 */
163 	public static void memProfile()
164 	{
165 		g_mem_profile();
166 	}
167 
168 	/**
169 	 * This function used to let you override the memory allocation function.
170 	 * However, its use was incompatible with the use of global constructors
171 	 * in GLib and GIO, because those use the GLib allocators before main is
172 	 * reached. Therefore this function is now deprecated and is just a stub.
173 	 *
174 	 * Deprecated: This function now does nothing. Use other memory
175 	 * profiling tools instead
176 	 *
177 	 * Params:
178 	 *     vtable = table of memory allocation routines.
179 	 */
180 	public static void memSetVtable(GMemVTable* vtable)
181 	{
182 		g_mem_set_vtable(vtable);
183 	}
184 
185 	/**
186 	 * Allocates @byte_size bytes of memory, and copies @byte_size bytes into it
187 	 * from @mem. If @mem is %NULL it returns %NULL.
188 	 *
189 	 * Deprecated: Use g_memdup2() instead, as it accepts a #gsize argument
190 	 * for @byte_size, avoiding the possibility of overflow in a #gsize → #guint
191 	 * conversion
192 	 *
193 	 * Params:
194 	 *     mem = the memory to copy.
195 	 *     byteSize = the number of bytes to copy.
196 	 *
197 	 * Returns: a pointer to the newly-allocated copy of the memory, or %NULL if @mem
198 	 *     is %NULL.
199 	 */
200 	public static void* memdup(void* mem, uint byteSize)
201 	{
202 		return g_memdup(mem, byteSize);
203 	}
204 
205 	/**
206 	 * Reallocates the memory pointed to by @mem, so that it now has space for
207 	 * @n_bytes bytes of memory. It returns the new address of the memory, which may
208 	 * have been moved. @mem may be %NULL, in which case it's considered to
209 	 * have zero-length. @n_bytes may be 0, in which case %NULL will be returned
210 	 * and @mem will be freed unless it is %NULL.
211 	 *
212 	 * Params:
213 	 *     mem = the memory to reallocate
214 	 *     nBytes = new size of the memory in bytes
215 	 *
216 	 * Returns: the new address of the allocated memory
217 	 */
218 	public static void* realloc(void* mem, size_t nBytes)
219 	{
220 		return g_realloc(mem, nBytes);
221 	}
222 
223 	/**
224 	 * This function is similar to g_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
225 	 * but care is taken to detect possible overflow during multiplication.
226 	 *
227 	 * Params:
228 	 *     mem = the memory to reallocate
229 	 *     nBlocks = the number of blocks to allocate
230 	 *     nBlockBytes = the size of each block in bytes
231 	 *
232 	 * Returns: the new address of the allocated memory
233 	 *
234 	 * Since: 2.24
235 	 */
236 	public static void* reallocN(void* mem, size_t nBlocks, size_t nBlockBytes)
237 	{
238 		return g_realloc_n(mem, nBlocks, nBlockBytes);
239 	}
240 
241 	/**
242 	 * Attempts to allocate @n_bytes, and returns %NULL on failure.
243 	 * Contrast with g_malloc(), which aborts the program on failure.
244 	 *
245 	 * Params:
246 	 *     nBytes = number of bytes to allocate.
247 	 *
248 	 * Returns: the allocated memory, or %NULL.
249 	 */
250 	public static void* tryMalloc(size_t nBytes)
251 	{
252 		return g_try_malloc(nBytes);
253 	}
254 
255 	/**
256 	 * Attempts to allocate @n_bytes, initialized to 0's, and returns %NULL on
257 	 * failure. Contrast with g_malloc0(), which aborts the program on failure.
258 	 *
259 	 * Params:
260 	 *     nBytes = number of bytes to allocate
261 	 *
262 	 * Returns: the allocated memory, or %NULL
263 	 *
264 	 * Since: 2.8
265 	 */
266 	public static void* tryMalloc0(size_t nBytes)
267 	{
268 		return g_try_malloc0(nBytes);
269 	}
270 
271 	/**
272 	 * This function is similar to g_try_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
273 	 * but care is taken to detect possible overflow during multiplication.
274 	 *
275 	 * Params:
276 	 *     nBlocks = the number of blocks to allocate
277 	 *     nBlockBytes = the size of each block in bytes
278 	 *
279 	 * Returns: the allocated memory, or %NULL
280 	 *
281 	 * Since: 2.24
282 	 */
283 	public static void* tryMalloc0N(size_t nBlocks, size_t nBlockBytes)
284 	{
285 		return g_try_malloc0_n(nBlocks, nBlockBytes);
286 	}
287 
288 	/**
289 	 * This function is similar to g_try_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
290 	 * but care is taken to detect possible overflow during multiplication.
291 	 *
292 	 * Params:
293 	 *     nBlocks = the number of blocks to allocate
294 	 *     nBlockBytes = the size of each block in bytes
295 	 *
296 	 * Returns: the allocated memory, or %NULL.
297 	 *
298 	 * Since: 2.24
299 	 */
300 	public static void* tryMallocN(size_t nBlocks, size_t nBlockBytes)
301 	{
302 		return g_try_malloc_n(nBlocks, nBlockBytes);
303 	}
304 
305 	/**
306 	 * Attempts to realloc @mem to a new size, @n_bytes, and returns %NULL
307 	 * on failure. Contrast with g_realloc(), which aborts the program
308 	 * on failure.
309 	 *
310 	 * If @mem is %NULL, behaves the same as g_try_malloc().
311 	 *
312 	 * Params:
313 	 *     mem = previously-allocated memory, or %NULL.
314 	 *     nBytes = number of bytes to allocate.
315 	 *
316 	 * Returns: the allocated memory, or %NULL.
317 	 */
318 	public static void* tryRealloc(void* mem, size_t nBytes)
319 	{
320 		return g_try_realloc(mem, nBytes);
321 	}
322 
323 	/**
324 	 * This function is similar to g_try_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
325 	 * but care is taken to detect possible overflow during multiplication.
326 	 *
327 	 * Params:
328 	 *     mem = previously-allocated memory, or %NULL.
329 	 *     nBlocks = the number of blocks to allocate
330 	 *     nBlockBytes = the size of each block in bytes
331 	 *
332 	 * Returns: the allocated memory, or %NULL.
333 	 *
334 	 * Since: 2.24
335 	 */
336 	public static void* tryReallocN(void* mem, size_t nBlocks, size_t nBlockBytes)
337 	{
338 		return g_try_realloc_n(mem, nBlocks, nBlockBytes);
339 	}
340 }