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