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