Use this to allocate large blocks of memory for T. This is useful for large arrays or objects that need to be allocated in a single block.
| 217 | // This is useful for large arrays or objects that need to be allocated |
| 218 | // in a single block. |
| 219 | T* allocate(fl::size n) FL_NOEXCEPT { |
| 220 | if (n == 0) { |
| 221 | return nullptr; // Handle zero allocation |
| 222 | } |
| 223 | fl::size size = sizeof(T) * n; |
| 224 | void *ptr = Malloc(size); |
| 225 | if (ptr == nullptr) { |
| 226 | return nullptr; // Handle allocation failure |
| 227 | } |
| 228 | fl::memset(ptr, 0, sizeof(T) * n); // Zero-initialize the memory |
| 229 | return static_cast<T*>(ptr); |
| 230 | } |
| 231 | |
| 232 | void deallocate(T* p, fl::size n) FL_NOEXCEPT { |
| 233 | FASTLED_UNUSED(n); |
no test coverage detected