我试图在函数中使用malloc返回一个数组:
char* queueBulkDequeue(queueADT queue, unsigned int size)
{
unsigned int i;
char* pElements=(char*)malloc(size * sizeof(char));
for (i=0; i<size; i++)
{
*(pElements+i) = queueDequeue(queue);
}
return pElements;
}
Run Code Online (Sandbox Code Playgroud)
问题是我需要释放它,因为我的MCU堆大小有限.但是我想退回它,所以我不能在功能中释放它,对吧?我可以在函数外部释放已分配的内存(我称之为函数).这有什么最佳做法吗?先感谢您!