FastLED 3.9.15
Loading...
Searching...
No Matches

◆ aligned_alloc()

void * fl::aligned_alloc ( fl::size_t alignment,
fl::size_t size )

Definition at line 21 of file cstdlib.cpp.hpp.

21 {
22#if defined(FL_IS_AVR) || defined(FL_IS_ESP8266) || defined(FL_IS_ARM) || defined(FL_IS_APOLLO3)
23 // Many bare-metal toolchains (newlib-nano on STM32, nRF52, SAMD, RP2040,
24 // Teensy, etc.) ship an aligned_alloc that internally calls
25 // posix_memalign, which doesn't exist on bare-metal and causes an
26 // "undefined reference to `posix_memalign'" link error.
27 // Fall back to plain malloc — sufficient for the alignments FastLED
28 // actually requests on these constrained targets.
29 (void)alignment;
30 return ::malloc(size);
31#elif defined(FL_IS_WIN)
32 return ::_aligned_malloc(size, alignment);
33#elif defined(FL_IS_ESP32) && !ESP_IDF_VERSION_4_OR_HIGHER
34 // ESP-IDF 3.x toolchain (GCC 5.2 / newlib) does not provide
35 // ::aligned_alloc. Fall back to plain malloc.
36 (void)alignment;
37 return ::malloc(size);
38#else
39 fl::size_t aligned_size = (size + alignment - 1) & ~(alignment - 1);
40 return ::aligned_alloc(alignment, aligned_size);
41#endif
42}
__SIZE_TYPE__ size_t
Definition s16x16x4.h:16