This is my code:
uint16_t * ptemparr = new uint16_t[20];
for (int x=0;x<2;x++)
{
function(ptemparr);
ptemparr ++;
}
delete[] ptemparr;
When I do that I get this error:
double free or corruption (out)
EDITED:
Thank you I understood why I get this error, now do you think this is a better idea?
uint16_t temparr[20];
uint16_t * ptemparr = temparr;
for (int x=0;x<2;x++)
{
function(ptemparr);
ptemparr ++;
}
This way I make the pointer on the stack and there’s no memory leak issue.
Also, this code above has to run every 1 sec, so please bare this in mind before letting me know what’s the best coding practice for this situation
You need to pass the same address to
delete []which was returned bynew [].Also, make sure
function()does notdeallocate the memory by callingdelete`on the passed pointer.