Blender V5.3
cycles/util/aligned_malloc.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include <cstddef>
8
10
11/* Minimum alignment needed by all CPU native data types (SSE, AVX). */
12#define MIN_ALIGNMENT_CPU_DATA_TYPES 16 // NOLINT
13/* NanoVDB needs at least 32 byte alignment. */
14#define MIN_ALIGNMENT_DEVICE_MEMORY 32 // NOLINT
15
16/* Allocate block of size bytes at least aligned to a given value. */
17void *util_aligned_malloc(const size_t size, const int alignment);
18void *util_page_aligned_malloc(const size_t size);
19
20/* Free memory allocated by util_aligned_malloc. */
21void util_aligned_free(void *ptr, const size_t size);
22void util_page_aligned_free(void *ptr, const size_t size);
23
24/* Aligned new operator. */
25template<typename T, typename... Args> T *util_aligned_new(Args... args)
26{
27 void *mem = util_aligned_malloc(sizeof(T), alignof(T));
28 return new (mem) T(args...);
29}
30
31template<typename T> void util_aligned_delete(T *t)
32{
33 if (t) {
34 t->~T();
35 util_aligned_free(t, sizeof(T));
36 }
37}
38
void * util_page_aligned_malloc(const size_t size)
void util_page_aligned_free(void *ptr, const size_t size)
CCL_NAMESPACE_BEGIN void * util_aligned_malloc(const size_t size, const int alignment)
void util_aligned_free(void *ptr, const size_t size)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
T * util_aligned_new(Args... args)
void util_aligned_delete(T *t)
#define CCL_NAMESPACE_END
#define T