MCPcopy Create free account
hub / github.com/coin-or/CppAD / check_alignment

Function check_alignment

example/utility/thread_alloc.cpp:154–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152} // End empty namespace
153
154bool check_alignment(void)
155{ bool ok = true;
156 using CppAD::thread_alloc;
157
158 // number of binary digits in a size_t value
159 size_t n_digit = std::numeric_limits<size_t>::digits;
160
161 // must be a multiple of 8
162 ok &= (n_digit % 8) == 0;
163
164 // number of bytes in a size_t value
165 size_t n_byte = n_digit / 8;
166
167 // check raw allocation -------------------------------------------------
168 size_t min_bytes = 1;
169 size_t cap_bytes;
170 void* v_ptr = thread_alloc::get_memory(min_bytes, cap_bytes);
171
172 // convert to a size_t value
173 size_t v_size_t = reinterpret_cast<size_t>(v_ptr);
174
175 // check that it is aligned
176 ok &= (v_size_t % n_byte) == 0;
177
178 // return memory to available pool
179 thread_alloc::return_memory(v_ptr);
180
181 // check array allocation ----------------------------------------------
182 size_t size_min = 1;
183 size_t size_out;
184 my_char *array_ptr =
185 thread_alloc::create_array<my_char>(size_min, size_out);
186
187 // convert to a size_t value
188 size_t array_size_t = reinterpret_cast<size_t>(array_ptr);
189
190 // check that it is aligned
191 ok &= (array_size_t % n_byte) == 0;
192
193 // return memory to available pool
194 thread_alloc::delete_array(array_ptr);
195
196 return ok;
197}
198
199
200bool thread_alloc(void)

Callers 1

thread_allocFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected