File: Memory.d

package info (click to toggle)
gtk-d 3.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 20,152 kB
  • sloc: javascript: 565; sh: 71; makefile: 25
file content (337 lines) | stat: -rw-r--r-- 9,759 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
 * This file is part of gtkD.
 *
 * gtkD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version, with
 * some exceptions, please read the COPYING file.
 *
 * gtkD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with gtkD; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 */

// generated automatically - do not change
// find conversion definition on APILookup.txt
// implement new conversion functionalities on the wrap.utils pakage


module glib.Memory;

private import glib.c.functions;
public  import glib.c.types;
public  import gtkc.glibtypes;


/** */
public struct Memory
{

	/**
	 * Clears a reference to a variable.
	 *
	 * @pp must not be %NULL.
	 *
	 * If the reference is %NULL then this function does nothing.
	 * Otherwise, the variable is destroyed using @destroy and the
	 * pointer is set to %NULL.
	 *
	 * A macro is also included that allows this function to be used without
	 * pointer casts. This will mask any warnings about incompatible function types
	 * or calling conventions, so you must ensure that your @destroy function is
	 * compatible with being called as `GDestroyNotify` using the standard calling
	 * convention for the platform that GLib was compiled for; otherwise the program
	 * will experience undefined behaviour.
	 *
	 * Params:
	 *     pp = a pointer to a variable, struct member etc. holding a
	 *         pointer
	 *     destroy = a function to which a gpointer can be passed, to destroy *@pp
	 *
	 * Since: 2.34
	 */
	public static void clearPointer(void** pp, GDestroyNotify destroy)
	{
		g_clear_pointer(pp, destroy);
	}

	/**
	 * Frees the memory pointed to by @mem.
	 *
	 * If @mem is %NULL it simply returns, so there is no need to check @mem
	 * against %NULL before calling this function.
	 *
	 * Params:
	 *     mem = the memory to free
	 */
	public static void free(void* mem)
	{
		g_free(mem);
	}

	/**
	 * Allocates @n_bytes bytes of memory.
	 * If @n_bytes is 0 it returns %NULL.
	 *
	 * Params:
	 *     nBytes = the number of bytes to allocate
	 *
	 * Returns: a pointer to the allocated memory
	 */
	public static void* malloc(size_t nBytes)
	{
		return g_malloc(nBytes);
	}

	/**
	 * Allocates @n_bytes bytes of memory, initialized to 0's.
	 * If @n_bytes is 0 it returns %NULL.
	 *
	 * Params:
	 *     nBytes = the number of bytes to allocate
	 *
	 * Returns: a pointer to the allocated memory
	 */
	public static void* malloc0(size_t nBytes)
	{
		return g_malloc0(nBytes);
	}

	/**
	 * This function is similar to g_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
	 * but care is taken to detect possible overflow during multiplication.
	 *
	 * Params:
	 *     nBlocks = the number of blocks to allocate
	 *     nBlockBytes = the size of each block in bytes
	 *
	 * Returns: a pointer to the allocated memory
	 *
	 * Since: 2.24
	 */
	public static void* malloc0N(size_t nBlocks, size_t nBlockBytes)
	{
		return g_malloc0_n(nBlocks, nBlockBytes);
	}

	/**
	 * This function is similar to g_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
	 * but care is taken to detect possible overflow during multiplication.
	 *
	 * Params:
	 *     nBlocks = the number of blocks to allocate
	 *     nBlockBytes = the size of each block in bytes
	 *
	 * Returns: a pointer to the allocated memory
	 *
	 * Since: 2.24
	 */
	public static void* mallocN(size_t nBlocks, size_t nBlockBytes)
	{
		return g_malloc_n(nBlocks, nBlockBytes);
	}

	/**
	 * Checks whether the allocator used by g_malloc() is the system's
	 * malloc implementation. If it returns %TRUE memory allocated with
	 * malloc() can be used interchangeably with memory allocated using g_malloc().
	 * This function is useful for avoiding an extra copy of allocated memory returned
	 * by a non-GLib-based API.
	 *
	 * Deprecated: GLib always uses the system malloc, so this function always
	 * returns %TRUE.
	 *
	 * Returns: if %TRUE, malloc() and g_malloc() can be mixed.
	 */
	public static bool memIsSystemMalloc()
	{
		return g_mem_is_system_malloc() != 0;
	}

	/**
	 * GLib used to support some tools for memory profiling, but this
	 * no longer works. There are many other useful tools for memory
	 * profiling these days which can be used instead.
	 *
	 * Deprecated: Use other memory profiling tools instead
	 */
	public static void memProfile()
	{
		g_mem_profile();
	}

	/**
	 * This function used to let you override the memory allocation function.
	 * However, its use was incompatible with the use of global constructors
	 * in GLib and GIO, because those use the GLib allocators before main is
	 * reached. Therefore this function is now deprecated and is just a stub.
	 *
	 * Deprecated: This function now does nothing. Use other memory
	 * profiling tools instead
	 *
	 * Params:
	 *     vtable = table of memory allocation routines.
	 */
	public static void memSetVtable(GMemVTable* vtable)
	{
		g_mem_set_vtable(vtable);
	}

	/**
	 * Allocates @byte_size bytes of memory, and copies @byte_size bytes into it
	 * from @mem. If @mem is %NULL it returns %NULL.
	 *
	 * Params:
	 *     mem = the memory to copy.
	 *     byteSize = the number of bytes to copy.
	 *
	 * Returns: a pointer to the newly-allocated copy of the memory, or %NULL if @mem
	 *     is %NULL.
	 */
	public static void* memdup(void* mem, uint byteSize)
	{
		return g_memdup(mem, byteSize);
	}

	/**
	 * Reallocates the memory pointed to by @mem, so that it now has space for
	 * @n_bytes bytes of memory. It returns the new address of the memory, which may
	 * have been moved. @mem may be %NULL, in which case it's considered to
	 * have zero-length. @n_bytes may be 0, in which case %NULL will be returned
	 * and @mem will be freed unless it is %NULL.
	 *
	 * Params:
	 *     mem = the memory to reallocate
	 *     nBytes = new size of the memory in bytes
	 *
	 * Returns: the new address of the allocated memory
	 */
	public static void* realloc(void* mem, size_t nBytes)
	{
		return g_realloc(mem, nBytes);
	}

	/**
	 * This function is similar to g_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
	 * but care is taken to detect possible overflow during multiplication.
	 *
	 * Params:
	 *     mem = the memory to reallocate
	 *     nBlocks = the number of blocks to allocate
	 *     nBlockBytes = the size of each block in bytes
	 *
	 * Returns: the new address of the allocated memory
	 *
	 * Since: 2.24
	 */
	public static void* reallocN(void* mem, size_t nBlocks, size_t nBlockBytes)
	{
		return g_realloc_n(mem, nBlocks, nBlockBytes);
	}

	/**
	 * Attempts to allocate @n_bytes, and returns %NULL on failure.
	 * Contrast with g_malloc(), which aborts the program on failure.
	 *
	 * Params:
	 *     nBytes = number of bytes to allocate.
	 *
	 * Returns: the allocated memory, or %NULL.
	 */
	public static void* tryMalloc(size_t nBytes)
	{
		return g_try_malloc(nBytes);
	}

	/**
	 * Attempts to allocate @n_bytes, initialized to 0's, and returns %NULL on
	 * failure. Contrast with g_malloc0(), which aborts the program on failure.
	 *
	 * Params:
	 *     nBytes = number of bytes to allocate
	 *
	 * Returns: the allocated memory, or %NULL
	 *
	 * Since: 2.8
	 */
	public static void* tryMalloc0(size_t nBytes)
	{
		return g_try_malloc0(nBytes);
	}

	/**
	 * This function is similar to g_try_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
	 * but care is taken to detect possible overflow during multiplication.
	 *
	 * Params:
	 *     nBlocks = the number of blocks to allocate
	 *     nBlockBytes = the size of each block in bytes
	 *
	 * Returns: the allocated memory, or %NULL
	 *
	 * Since: 2.24
	 */
	public static void* tryMalloc0N(size_t nBlocks, size_t nBlockBytes)
	{
		return g_try_malloc0_n(nBlocks, nBlockBytes);
	}

	/**
	 * This function is similar to g_try_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
	 * but care is taken to detect possible overflow during multiplication.
	 *
	 * Params:
	 *     nBlocks = the number of blocks to allocate
	 *     nBlockBytes = the size of each block in bytes
	 *
	 * Returns: the allocated memory, or %NULL.
	 *
	 * Since: 2.24
	 */
	public static void* tryMallocN(size_t nBlocks, size_t nBlockBytes)
	{
		return g_try_malloc_n(nBlocks, nBlockBytes);
	}

	/**
	 * Attempts to realloc @mem to a new size, @n_bytes, and returns %NULL
	 * on failure. Contrast with g_realloc(), which aborts the program
	 * on failure.
	 *
	 * If @mem is %NULL, behaves the same as g_try_malloc().
	 *
	 * Params:
	 *     mem = previously-allocated memory, or %NULL.
	 *     nBytes = number of bytes to allocate.
	 *
	 * Returns: the allocated memory, or %NULL.
	 */
	public static void* tryRealloc(void* mem, size_t nBytes)
	{
		return g_try_realloc(mem, nBytes);
	}

	/**
	 * This function is similar to g_try_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
	 * but care is taken to detect possible overflow during multiplication.
	 *
	 * Params:
	 *     mem = previously-allocated memory, or %NULL.
	 *     nBlocks = the number of blocks to allocate
	 *     nBlockBytes = the size of each block in bytes
	 *
	 * Returns: the allocated memory, or %NULL.
	 *
	 * Since: 2.24
	 */
	public static void* tryReallocN(void* mem, size_t nBlocks, size_t nBlockBytes)
	{
		return g_try_realloc_n(mem, nBlocks, nBlockBytes);
	}
}