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:
@@ -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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user