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.
This commit is contained in:
parent
001abe5262
commit
8fafd6cba6
1 changed files with 5 additions and 2 deletions
|
@ -29,7 +29,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
|
||||
|
@ -38,7 +38,10 @@ static nRF5xn deviceInstance;
|
|||
BLEInstanceBase *
|
||||
createBLEInstance(void)
|
||||
{
|
||||
return (&deviceInstance);
|
||||
if (deviceInstance == NULL)
|
||||
deviceInstance = new nRF5xn();
|
||||
|
||||
return (deviceInstance);
|
||||
}
|
||||
|
||||
nRF5xn::nRF5xn(void) : initialized(false), instanceID(BLE::DEFAULT_INSTANCE)
|
||||
|
|
Loading…
Reference in a new issue