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