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 /** */ 32 public struct Memory 33 { 34 35 /** 36 * Clears a reference to a variable. 37 * 38 * @pp must not be %NULL. 39 * 40 * If the reference is %NULL then this function does nothing. 41 * Otherwise, the variable is destroyed using @destroy and the 42 * pointer is set to %NULL. 43 * 44 * A macro is also included that allows this function to be used without 45 * pointer casts. 46 * 47 * Params: 48 * pp = a pointer to a variable, struct member etc. holding a 49 * 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 * Returns: 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 * Returns: 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 * Returns: 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 * Returns: 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 * Deprecated: GLib always uses the system malloc, so this function always 143 * returns %TRUE. 144 * 145 * Returns: if %TRUE, malloc() and g_malloc() can be mixed. 146 */ 147 public static bool memIsSystemMalloc() 148 { 149 return g_mem_is_system_malloc() != 0; 150 } 151 152 /** 153 * GLib used to support some tools for memory profiling, but this 154 * no longer works. There are many other useful tools for memory 155 * profiling these days which can be used instead. 156 * 157 * Deprecated: Use other memory profiling tools instead 158 */ 159 public static void memProfile() 160 { 161 g_mem_profile(); 162 } 163 164 /** 165 * This function used to let you override the memory allocation function. 166 * However, its use was incompatible with the use of global constructors 167 * in GLib and GIO, because those use the GLib allocators before main is 168 * reached. Therefore this function is now deprecated and is just a stub. 169 * 170 * Deprecated: Use other memory profiling tools instead 171 * 172 * Params: 173 * vtable = table of memory allocation routines. 174 */ 175 public static void memSetVtable(GMemVTable* vtable) 176 { 177 g_mem_set_vtable(vtable); 178 } 179 180 /** 181 * Allocates @byte_size bytes of memory, and copies @byte_size bytes into it 182 * from @mem. If @mem is %NULL it returns %NULL. 183 * 184 * Params: 185 * mem = the memory to copy. 186 * byteSize = the number of bytes to copy. 187 * 188 * Returns: a pointer to the newly-allocated copy of the memory, or %NULL if @mem 189 * is %NULL. 190 */ 191 public static void* memdup(void* mem, uint byteSize) 192 { 193 return g_memdup(mem, byteSize); 194 } 195 196 /** 197 * Reallocates the memory pointed to by @mem, so that it now has space for 198 * @n_bytes bytes of memory. It returns the new address of the memory, which may 199 * have been moved. @mem may be %NULL, in which case it's considered to 200 * have zero-length. @n_bytes may be 0, in which case %NULL will be returned 201 * and @mem will be freed unless it is %NULL. 202 * 203 * Params: 204 * mem = the memory to reallocate 205 * nBytes = new size of the memory in bytes 206 * 207 * Returns: the new address of the allocated memory 208 */ 209 public static void* realloc(void* mem, size_t nBytes) 210 { 211 return g_realloc(mem, nBytes); 212 } 213 214 /** 215 * This function is similar to g_realloc(), allocating (@n_blocks * @n_block_bytes) bytes, 216 * but care is taken to detect possible overflow during multiplication. 217 * 218 * Params: 219 * mem = the memory to reallocate 220 * nBlocks = the number of blocks to allocate 221 * nBlockBytes = the size of each block in bytes 222 * 223 * Returns: the new address of the allocated memory 224 * 225 * Since: 2.24 226 */ 227 public static void* reallocN(void* mem, size_t nBlocks, size_t nBlockBytes) 228 { 229 return g_realloc_n(mem, nBlocks, nBlockBytes); 230 } 231 232 /** 233 * Attempts to allocate @n_bytes, and returns %NULL on failure. 234 * Contrast with g_malloc(), which aborts the program on failure. 235 * 236 * Params: 237 * nBytes = number of bytes to allocate. 238 * 239 * Returns: the allocated memory, or %NULL. 240 */ 241 public static void* tryMalloc(size_t nBytes) 242 { 243 return g_try_malloc(nBytes); 244 } 245 246 /** 247 * Attempts to allocate @n_bytes, initialized to 0's, and returns %NULL on 248 * failure. Contrast with g_malloc0(), which aborts the program on failure. 249 * 250 * Params: 251 * nBytes = number of bytes to allocate 252 * 253 * Returns: the allocated memory, or %NULL 254 * 255 * Since: 2.8 256 */ 257 public static void* tryMalloc0(size_t nBytes) 258 { 259 return g_try_malloc0(nBytes); 260 } 261 262 /** 263 * This function is similar to g_try_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes, 264 * but care is taken to detect possible overflow during multiplication. 265 * 266 * Params: 267 * nBlocks = the number of blocks to allocate 268 * nBlockBytes = the size of each block in bytes 269 * 270 * Returns: the allocated memory, or %NULL 271 * 272 * Since: 2.24 273 */ 274 public static void* tryMalloc0N(size_t nBlocks, size_t nBlockBytes) 275 { 276 return g_try_malloc0_n(nBlocks, nBlockBytes); 277 } 278 279 /** 280 * This function is similar to g_try_malloc(), allocating (@n_blocks * @n_block_bytes) bytes, 281 * but care is taken to detect possible overflow during multiplication. 282 * 283 * Params: 284 * nBlocks = the number of blocks to allocate 285 * nBlockBytes = the size of each block in bytes 286 * 287 * Returns: the allocated memory, or %NULL. 288 * 289 * Since: 2.24 290 */ 291 public static void* tryMallocN(size_t nBlocks, size_t nBlockBytes) 292 { 293 return g_try_malloc_n(nBlocks, nBlockBytes); 294 } 295 296 /** 297 * Attempts to realloc @mem to a new size, @n_bytes, and returns %NULL 298 * on failure. Contrast with g_realloc(), which aborts the program 299 * on failure. 300 * 301 * If @mem is %NULL, behaves the same as g_try_malloc(). 302 * 303 * Params: 304 * mem = previously-allocated memory, or %NULL. 305 * nBytes = number of bytes to allocate. 306 * 307 * Returns: the allocated memory, or %NULL. 308 */ 309 public static void* tryRealloc(void* mem, size_t nBytes) 310 { 311 return g_try_realloc(mem, nBytes); 312 } 313 314 /** 315 * This function is similar to g_try_realloc(), allocating (@n_blocks * @n_block_bytes) bytes, 316 * but care is taken to detect possible overflow during multiplication. 317 * 318 * Params: 319 * mem = previously-allocated memory, or %NULL. 320 * nBlocks = the number of blocks to allocate 321 * nBlockBytes = the size of each block in bytes 322 * 323 * Returns: the allocated memory, or %NULL. 324 * 325 * Since: 2.24 326 */ 327 public static void* tryReallocN(void* mem, size_t nBlocks, size_t nBlockBytes) 328 { 329 return g_try_realloc_n(mem, nBlocks, nBlockBytes); 330 } 331 }