Blender V4.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#ifndef __UTIL_ALIGNED_MALLOC_H__
6#define __UTIL_ALIGNED_MALLOC_H__
7
8#include "util/types.h"
9
11
12/* Minimum alignment needed by all CPU native data types (SSE, AVX). */
13#define MIN_ALIGNMENT_CPU_DATA_TYPES 16
14
15/* Allocate block of size bytes at least aligned to a given value. */
16void *util_aligned_malloc(size_t size, int alignment);
17
18/* Free memory allocated by util_aligned_malloc. */
19void util_aligned_free(void *ptr);
20
21/* Aligned new operator. */
22template<typename T, typename... Args> T *util_aligned_new(Args... args)
23{
24 void *mem = util_aligned_malloc(sizeof(T), alignof(T));
25 return new (mem) T(args...);
26}
27
28template<typename T> void util_aligned_delete(T *t)
29{
30 if (t) {
31 t->~T();
33 }
34}
35
37
38#endif /* __UTIL_ALIGNED_MALLOC_H__ */
void util_aligned_free(void *ptr)
T * util_aligned_new(Args... args)
void util_aligned_delete(T *t)
void * util_aligned_malloc(size_t size, int alignment)
#define CCL_NAMESPACE_END
#define T
PointerRNA * ptr
Definition wm_files.cc:4126