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.MemorySlice; 26 27 private import glib.c.functions; 28 public import glib.c.types; 29 public import gtkc.glibtypes; 30 31 32 /** */ 33 public struct MemorySlice 34 { 35 public static T* mewSlice(T)() 36 { 37 return cast(T*)g_slice_alloc(T.sizeof); 38 } 39 40 public static T* mewSlice0(T)() 41 { 42 return cast(T*)g_slice_alloc0(T.sizeof); 43 } 44 45 public static T* dup(T)(T* memBlock) 46 { 47 return cast(T*)g_slice_copy(T.sizeof, memBlock); 48 } 49 50 public static void free(T)(T* memBlock) 51 { 52 g_slice_free1(T.sizeof, memBlock); 53 } 54 55 /** 56 */ 57 58 /** 59 * Allocates a block of memory from the slice allocator. 60 * The block adress handed out can be expected to be aligned 61 * to at least 1 * sizeof (void*), 62 * though in general slices are 2 * sizeof (void*) bytes aligned, 63 * if a malloc() fallback implementation is used instead, 64 * the alignment may be reduced in a libc dependent fashion. 65 * Note that the underlying slice allocation mechanism can 66 * be changed with the [`G_SLICE=always-malloc`][G_SLICE] 67 * environment variable. 68 * 69 * Params: 70 * blockSize = the number of bytes to allocate 71 * 72 * Returns: a pointer to the allocated memory block, which will be %NULL if and 73 * only if @mem_size is 0 74 * 75 * Since: 2.10 76 */ 77 public static void* sliceAlloc(size_t blockSize) 78 { 79 return g_slice_alloc(blockSize); 80 } 81 82 /** 83 * Allocates a block of memory via g_slice_alloc() and initializes 84 * the returned memory to 0. Note that the underlying slice allocation 85 * mechanism can be changed with the [`G_SLICE=always-malloc`][G_SLICE] 86 * environment variable. 87 * 88 * Params: 89 * blockSize = the number of bytes to allocate 90 * 91 * Returns: a pointer to the allocated block, which will be %NULL if and only 92 * if @mem_size is 0 93 * 94 * Since: 2.10 95 */ 96 public static void* sliceAlloc0(size_t blockSize) 97 { 98 return g_slice_alloc0(blockSize); 99 } 100 101 /** 102 * Allocates a block of memory from the slice allocator 103 * and copies @block_size bytes into it from @mem_block. 104 * 105 * @mem_block must be non-%NULL if @block_size is non-zero. 106 * 107 * Params: 108 * blockSize = the number of bytes to allocate 109 * memBlock = the memory to copy 110 * 111 * Returns: a pointer to the allocated memory block, which will be %NULL if and 112 * only if @mem_size is 0 113 * 114 * Since: 2.14 115 */ 116 public static void* sliceCopy(size_t blockSize, void* memBlock) 117 { 118 return g_slice_copy(blockSize, memBlock); 119 } 120 121 /** 122 * Frees a block of memory. 123 * 124 * The memory must have been allocated via g_slice_alloc() or 125 * g_slice_alloc0() and the @block_size has to match the size 126 * specified upon allocation. Note that the exact release behaviour 127 * can be changed with the [`G_DEBUG=gc-friendly`][G_DEBUG] environment 128 * variable, also see [`G_SLICE`][G_SLICE] for related debugging options. 129 * 130 * If @mem_block is %NULL, this function does nothing. 131 * 132 * Params: 133 * blockSize = the size of the block 134 * memBlock = a pointer to the block to free 135 * 136 * Since: 2.10 137 */ 138 public static void sliceFree1(size_t blockSize, void* memBlock) 139 { 140 g_slice_free1(blockSize, memBlock); 141 } 142 143 /** 144 * Frees a linked list of memory blocks of structure type @type. 145 * 146 * The memory blocks must be equal-sized, allocated via 147 * g_slice_alloc() or g_slice_alloc0() and linked together by a 148 * @next pointer (similar to #GSList). The offset of the @next 149 * field in each block is passed as third argument. 150 * Note that the exact release behaviour can be changed with the 151 * [`G_DEBUG=gc-friendly`][G_DEBUG] environment variable, also see 152 * [`G_SLICE`][G_SLICE] for related debugging options. 153 * 154 * If @mem_chain is %NULL, this function does nothing. 155 * 156 * Params: 157 * blockSize = the size of the blocks 158 * memChain = a pointer to the first block of the chain 159 * nextOffset = the offset of the @next field in the blocks 160 * 161 * Since: 2.10 162 */ 163 public static void sliceFreeChainWithOffset(size_t blockSize, void* memChain, size_t nextOffset) 164 { 165 g_slice_free_chain_with_offset(blockSize, memChain, nextOffset); 166 } 167 168 /** */ 169 public static long sliceGetConfig(GSliceConfig ckey) 170 { 171 return g_slice_get_config(ckey); 172 } 173 174 /** */ 175 public static long* sliceGetConfigState(GSliceConfig ckey, long address, uint* nValues) 176 { 177 return g_slice_get_config_state(ckey, address, nValues); 178 } 179 180 /** */ 181 public static void sliceSetConfig(GSliceConfig ckey, long value) 182 { 183 g_slice_set_config(ckey, value); 184 } 185 }