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