From 92905593f1031e0f89ff0b1667e4217282d0e634 Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Sat, 9 Jan 2016 11:33:02 +0000 Subject: [PATCH] microbit: Added support for MicroBitHeapAllocator to allocate C++ style array declarations Added missing operator new[] wrapper in MicroBitHeapAllocator.h Ammended defualt microBitConfig.h to allocate 90% of available heap, rather than 95%. this is to leave a little more heap for external libraries. --- inc/MicroBitConfig.h | 2 +- inc/MicroBitHeapAllocator.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/inc/MicroBitConfig.h b/inc/MicroBitConfig.h index d65b86f..274637b 100644 --- a/inc/MicroBitConfig.h +++ b/inc/MicroBitConfig.h @@ -39,7 +39,7 @@ // The proportion of SRAM available on the mbed heap to reserve for the micro:bit heap. #ifndef MICROBIT_HEAP_SIZE -#define MICROBIT_HEAP_SIZE 0.25 +#define MICROBIT_HEAP_SIZE 0.9 #endif // if defined, reuse the 8K of SRAM reserved for SoftDevice (Nordic's memory resident BLE stack) as heap memory. diff --git a/inc/MicroBitHeapAllocator.h b/inc/MicroBitHeapAllocator.h index fef6ffb..c8934c5 100644 --- a/inc/MicroBitHeapAllocator.h +++ b/inc/MicroBitHeapAllocator.h @@ -91,6 +91,14 @@ inline void* operator new(size_t size) throw(std::bad_alloc) return microbit_malloc(size); } +/** + * Overrides the 'new' operator globally, and redirects calls to the micro:bit theap allocator. + */ +inline void* operator new[](size_t size) throw(std::bad_alloc) +{ + return microbit_malloc(size); +} + /** * Overrides the 'delete' operator globally, and redirects calls to the micro:bit theap allocator. */