Private
Public Access
2
0

examples: Remove heap allocation from C++ examples

Small cleanup of MRAA C++ examples.  Switched from heap allocation to
stack allocation when possible.  This simplifies the samples since it
removes the need for explicit memory management.

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2017-08-08 13:55:23 -07:00
parent d50b646c35
commit 1217c5c034
7 changed files with 29 additions and 47 deletions

View File

@@ -44,20 +44,17 @@ main()
{
uint16_t adc_value;
float adc_value_float;
mraa::Aio* a0;
a0 = new mraa::Aio(0);
mraa::Aio a0(0);
signal(SIGINT, sig_handler);
while (running == 0) {
adc_value = a0->read();
adc_value_float = a0->readFloat();
adc_value = a0.read();
adc_value_float = a0.readFloat();
fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value);
fprintf(stdout, "ADC A0 read float - %.5f (Ctrl+C to exit)\n", adc_value_float);
}
delete a0;
return MRAA_SUCCESS;
}
//! [Interesting]