source: appstream-generator/build/girepo/glib/Memory.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 8.9 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module glib.Memory;
22
23private import gi.glib;
24public  import gi.glibtypes;
25
26
27/** */
28public struct Memory
29{
30
31        /**
32         * Clears a reference to a variable.
33         *
34         * @pp must not be %NULL.
35         *
36         * If the reference is %NULL then this function does nothing.
37         * Otherwise, the variable is destroyed using @destroy and the
38         * pointer is set to %NULL.
39         *
40         * A macro is also included that allows this function to be used without
41         * pointer casts.
42         *
43         * Params:
44         *     pp = a pointer to a variable, struct member etc. holding a pointer
45         *     destroy = a function to which a gpointer can be passed, to destroy *@pp
46         *
47         * Since: 2.34
48         */
49        public static void clearPointer(void** pp, GDestroyNotify destroy)
50        {
51                g_clear_pointer(pp, destroy);
52        }
53
54        /**
55         * Frees the memory pointed to by @mem.
56         *
57         * If @mem is %NULL it simply returns, so there is no need to check @mem
58         * against %NULL before calling this function.
59         *
60         * Params:
61         *     mem = the memory to free
62         */
63        public static void free(void* mem)
64        {
65                g_free(mem);
66        }
67
68        /**
69         * Allocates @n_bytes bytes of memory.
70         * If @n_bytes is 0 it returns %NULL.
71         *
72         * Params:
73         *     nBytes = the number of bytes to allocate
74         *
75         * Returns: a pointer to the allocated memory
76         */
77        public static void* malloc(size_t nBytes)
78        {
79                return g_malloc(nBytes);
80        }
81
82        /**
83         * Allocates @n_bytes bytes of memory, initialized to 0's.
84         * If @n_bytes is 0 it returns %NULL.
85         *
86         * Params:
87         *     nBytes = the number of bytes to allocate
88         *
89         * Returns: a pointer to the allocated memory
90         */
91        public static void* malloc0(size_t nBytes)
92        {
93                return g_malloc0(nBytes);
94        }
95
96        /**
97         * This function is similar to g_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
98         * but care is taken to detect possible overflow during multiplication.
99         *
100         * Params:
101         *     nBlocks = the number of blocks to allocate
102         *     nBlockBytes = the size of each block in bytes
103         *
104         * Returns: a pointer to the allocated memory
105         *
106         * Since: 2.24
107         */
108        public static void* malloc0N(size_t nBlocks, size_t nBlockBytes)
109        {
110                return g_malloc0_n(nBlocks, nBlockBytes);
111        }
112
113        /**
114         * This function is similar to g_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
115         * but care is taken to detect possible overflow during multiplication.
116         *
117         * Params:
118         *     nBlocks = the number of blocks to allocate
119         *     nBlockBytes = the size of each block in bytes
120         *
121         * Returns: a pointer to the allocated memory
122         *
123         * Since: 2.24
124         */
125        public static void* mallocN(size_t nBlocks, size_t nBlockBytes)
126        {
127                return g_malloc_n(nBlocks, nBlockBytes);
128        }
129
130        /**
131         * Checks whether the allocator used by g_malloc() is the system's
132         * malloc implementation. If it returns %TRUE memory allocated with
133         * malloc() can be used interchangeable with memory allocated using g_malloc().
134         * This function is useful for avoiding an extra copy of allocated memory returned
135         * by a non-GLib-based API.
136         *
137         * Deprecated: GLib always uses the system malloc, so this function always
138         * returns %TRUE.
139         *
140         * Returns: if %TRUE, malloc() and g_malloc() can be mixed.
141         */
142        public static bool memIsSystemMalloc()
143        {
144                return g_mem_is_system_malloc() != 0;
145        }
146
147        /**
148         * GLib used to support some tools for memory profiling, but this
149         * no longer works. There are many other useful tools for memory
150         * profiling these days which can be used instead.
151         *
152         * Deprecated: Use other memory profiling tools instead
153         */
154        public static void memProfile()
155        {
156                g_mem_profile();
157        }
158
159        /**
160         * This function used to let you override the memory allocation function.
161         * However, its use was incompatible with the use of global constructors
162         * in GLib and GIO, because those use the GLib allocators before main is
163         * reached. Therefore this function is now deprecated and is just a stub.
164         *
165         * Deprecated: Use other memory profiling tools instead
166         *
167         * Params:
168         *     vtable = table of memory allocation routines.
169         */
170        public static void memSetVtable(GMemVTable* vtable)
171        {
172                g_mem_set_vtable(vtable);
173        }
174
175        /**
176         * Allocates @byte_size bytes of memory, and copies @byte_size bytes into it
177         * from @mem. If @mem is %NULL it returns %NULL.
178         *
179         * Params:
180         *     mem = the memory to copy.
181         *     byteSize = the number of bytes to copy.
182         *
183         * Returns: a pointer to the newly-allocated copy of the memory, or %NULL if @mem
184         *     is %NULL.
185         */
186        public static void* memdup(void* mem, uint byteSize)
187        {
188                return g_memdup(mem, byteSize);
189        }
190
191        /**
192         * Reallocates the memory pointed to by @mem, so that it now has space for
193         * @n_bytes bytes of memory. It returns the new address of the memory, which may
194         * have been moved. @mem may be %NULL, in which case it's considered to
195         * have zero-length. @n_bytes may be 0, in which case %NULL will be returned
196         * and @mem will be freed unless it is %NULL.
197         *
198         * Params:
199         *     mem = the memory to reallocate
200         *     nBytes = new size of the memory in bytes
201         *
202         * Returns: the new address of the allocated memory
203         */
204        public static void* realloc(void* mem, size_t nBytes)
205        {
206                return g_realloc(mem, nBytes);
207        }
208
209        /**
210         * This function is similar to g_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
211         * but care is taken to detect possible overflow during multiplication.
212         *
213         * Params:
214         *     mem = the memory to reallocate
215         *     nBlocks = the number of blocks to allocate
216         *     nBlockBytes = the size of each block in bytes
217         *
218         * Returns: the new address of the allocated memory
219         *
220         * Since: 2.24
221         */
222        public static void* reallocN(void* mem, size_t nBlocks, size_t nBlockBytes)
223        {
224                return g_realloc_n(mem, nBlocks, nBlockBytes);
225        }
226
227        /**
228         * Attempts to allocate @n_bytes, and returns %NULL on failure.
229         * Contrast with g_malloc(), which aborts the program on failure.
230         *
231         * Params:
232         *     nBytes = number of bytes to allocate.
233         *
234         * Returns: the allocated memory, or %NULL.
235         */
236        public static void* tryMalloc(size_t nBytes)
237        {
238                return g_try_malloc(nBytes);
239        }
240
241        /**
242         * Attempts to allocate @n_bytes, initialized to 0's, and returns %NULL on
243         * failure. Contrast with g_malloc0(), 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         * Since: 2.8
251         */
252        public static void* tryMalloc0(size_t nBytes)
253        {
254                return g_try_malloc0(nBytes);
255        }
256
257        /**
258         * This function is similar to g_try_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
259         * but care is taken to detect possible overflow during multiplication.
260         *
261         * Params:
262         *     nBlocks = the number of blocks to allocate
263         *     nBlockBytes = the size of each block in bytes
264         *
265         * Returns: the allocated memory, or %NULL
266         *
267         * Since: 2.24
268         */
269        public static void* tryMalloc0N(size_t nBlocks, size_t nBlockBytes)
270        {
271                return g_try_malloc0_n(nBlocks, nBlockBytes);
272        }
273
274        /**
275         * This function is similar to g_try_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
276         * but care is taken to detect possible overflow during multiplication.
277         *
278         * Params:
279         *     nBlocks = the number of blocks to allocate
280         *     nBlockBytes = the size of each block in bytes
281         *
282         * Returns: the allocated memory, or %NULL.
283         *
284         * Since: 2.24
285         */
286        public static void* tryMallocN(size_t nBlocks, size_t nBlockBytes)
287        {
288                return g_try_malloc_n(nBlocks, nBlockBytes);
289        }
290
291        /**
292         * Attempts to realloc @mem to a new size, @n_bytes, and returns %NULL
293         * on failure. Contrast with g_realloc(), which aborts the program
294         * on failure.
295         *
296         * If @mem is %NULL, behaves the same as g_try_malloc().
297         *
298         * Params:
299         *     mem = previously-allocated memory, or %NULL.
300         *     nBytes = number of bytes to allocate.
301         *
302         * Returns: the allocated memory, or %NULL.
303         */
304        public static void* tryRealloc(void* mem, size_t nBytes)
305        {
306                return g_try_realloc(mem, nBytes);
307        }
308
309        /**
310         * This function is similar to g_try_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
311         * but care is taken to detect possible overflow during multiplication.
312         *
313         * Params:
314         *     mem = previously-allocated memory, or %NULL.
315         *     nBlocks = the number of blocks to allocate
316         *     nBlockBytes = the size of each block in bytes
317         *
318         * Returns: the allocated memory, or %NULL.
319         *
320         * Since: 2.24
321         */
322        public static void* tryReallocN(void* mem, size_t nBlocks, size_t nBlockBytes)
323        {
324                return g_try_realloc_n(mem, nBlocks, nBlockBytes);
325        }
326}
Note: See TracBrowser for help on using the repository browser.