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

@@ -55,21 +55,19 @@ main(int argc, char** argv)
signal(SIGINT, sig_handler);
//! [Interesting]
mraa::Gpio* gpio = new mraa::Gpio(iopin);
mraa::Result response = gpio->dir(mraa::DIR_OUT);
mraa::Gpio gpio(iopin);
mraa::Result response = gpio.dir(mraa::DIR_OUT);
if (response != mraa::SUCCESS) {
mraa::printError(response);
delete gpio;
return 1;
}
while (running == 0) {
response = gpio->write(1);
response = gpio.write(1);
sleep(1);
response = gpio->write(0);
response = gpio.write(0);
sleep(1);
}
delete gpio;
return response;
//! [Interesting]
}