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