\internal Allocates \a size bytes. The returned pointer is guaranteed to have 16 or 32 bytes alignment depending on * the requirements. On allocation error, the returned pointer is null, and std::bad_alloc is thrown. */
| 197 | * the requirements. On allocation error, the returned pointer is null, and std::bad_alloc is thrown. |
| 198 | */ |
| 199 | EIGEN_DEVICE_FUNC inline void* aligned_malloc(std::size_t size) { |
| 200 | if (size == 0) return nullptr; |
| 201 | |
| 202 | void* result; |
| 203 | #if (EIGEN_DEFAULT_ALIGN_BYTES == 0) || EIGEN_MALLOC_ALREADY_ALIGNED |
| 204 | |
| 205 | check_that_malloc_is_allowed(); |
| 206 | EIGEN_USING_STD(malloc) |
| 207 | result = malloc(size); |
| 208 | |
| 209 | #if EIGEN_DEFAULT_ALIGN_BYTES == 16 |
| 210 | eigen_assert((size < 16 || (std::size_t(result) % 16) == 0) && |
| 211 | "System's malloc returned an unaligned pointer. Compile with EIGEN_MALLOC_ALREADY_ALIGNED=0 to fallback " |
| 212 | "to handmade aligned memory allocator."); |
| 213 | #endif |
| 214 | #else |
| 215 | result = handmade_aligned_malloc(size); |
| 216 | #endif |
| 217 | |
| 218 | if (!result && size) throw_std_bad_alloc(); |
| 219 | |
| 220 | return result; |
| 221 | } |
| 222 | |
| 223 | /** \internal Frees memory allocated with aligned_malloc. */ |
| 224 | EIGEN_DEVICE_FUNC inline void aligned_free(void* ptr) { |
no test coverage detected