MCPcopy Create free account
hub / github.com/FastLED/FastLED / aligned_alloc

Function aligned_alloc

src/fl/stl/cstdlib.cpp.hpp:21–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19// ============================================================================
20
21void *aligned_alloc(fl::size_t alignment, fl::size_t size) {
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}
43
44void aligned_free(void *ptr) {
45#if defined(FL_IS_AVR) || defined(FL_IS_ESP8266) || defined(FL_IS_ARM) || defined(FL_IS_APOLLO3)

Callers 7

operator newFunction · 0.85
allocateBufferMethod · 0.85
allocateBufferMethod · 0.85
allocateDmaBufferMethod · 0.85
allocateFrameBufferMethod · 0.85
allocateBufferMethod · 0.85
allocateDmaBufferMethod · 0.85

Calls 1

mallocFunction · 0.70

Tested by

no test coverage detected