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