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