Eliminated use of exceptions in PSRAM.h and added -fno-exceptions

Added build_opt.h which include -fno-exceptions compiler instructions.  Seems to save about 29K of flash in compiled code (compiling for ESP32)
This commit is contained in:
Gregg 2024-05-02 20:45:30 -05:00
parent 1863cc4309
commit 8775a2df85
2 changed files with 8 additions and 4 deletions

View File

@ -45,11 +45,14 @@ template <class T>
struct Mallocator { struct Mallocator {
typedef T value_type; typedef T value_type;
Mallocator() = default; Mallocator() = default;
template <class U> constexpr Mallocator(const Mallocator<U>&) noexcept {} template <class U> constexpr Mallocator(const Mallocator<U>&) {}
[[nodiscard]] T* allocate(std::size_t n) { [[nodiscard]] T* allocate(std::size_t n) {
if(n > std::size_t(-1) / sizeof(T)) throw std::bad_alloc(); auto p = static_cast<T*>(HS_MALLOC(n*sizeof(T)));
if(auto p = static_cast<T*>(HS_MALLOC(n*sizeof(T)))) return p; if(p==NULL){
throw std::bad_alloc(); Serial.printf("\n\n*** FATAL ERROR: Requested allocation of %d bytes failed. Program Halting.\n\n",n*sizeof(T));
while(1);
}
return p;
} }
void deallocate(T* p, std::size_t) noexcept { std::free(p); } void deallocate(T* p, std::size_t) noexcept { std::free(p); }
}; };

1
src/build_opt.h Normal file
View File

@ -0,0 +1 @@
-fno-exceptions