microbit: BUGFIX: nRF5xn global singleton preventing gcc optimisation when module not initialized
A statically allocated nRF5xn singleton "deviceInstance" prevents gcc from optimising out the .bss memory used by the ble-nrf51822 module (approx 1.2K of RAM), even when the module is not used or initialised by application code. This can cause memory usage issues for heavily constrianed systems. This patch replaces the statically allocated singleton with an equivalent mechanism based on lazy instantiation. This approach permits gcc to optimise the code out when not in use.master
parent
d8227522cd
commit
d214d82075
|
@ -33,7 +33,7 @@ extern "C" {
|
|||
/**
|
||||
* The singleton which represents the nRF51822 transport for the BLE.
|
||||
*/
|
||||
static nRF5xn deviceInstance;
|
||||
static nRF5xn *deviceInstance = NULL;
|
||||
|
||||
/**
|
||||
* BLE-API requires an implementation of the following function in order to
|
||||
|
@ -47,7 +47,10 @@ createBLEInstance(void)
|
|||
|
||||
nRF5xn& nRF5xn::Instance(BLE::InstanceID_t instanceId)
|
||||
{
|
||||
return deviceInstance;
|
||||
if (deviceInstance == NULL)
|
||||
deviceInstance = new nRF5xn();
|
||||
|
||||
return *deviceInstance;
|
||||
}
|
||||
|
||||
nRF5xn::nRF5xn(void) :
|
||||
|
|
Loading…
Reference in New Issue