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