dynamic memory allocation NIOS

i am using dynamic memory allocation to run in NIOS. i) this means using malloc to get the memory needed ii) and using free to free the memory needed

after testing, i think that the free function does not do anything. is there any way to free the memory allocated?

Reply to
J-Wing
Loading thread data ...

Hi J-Wing,

I have not had problems using malloc or free on Nios. I created the following test code which shows malloc and free operating correctly. Note that I am attempting to allocate slightly over 1MB of memory; in this test I am only using SRAM on my Nios board, with is 1MB. If I comment out the free(buff) line, malloc() will fail as the memory is filled. When free(buff) is still in place, all malloc() operations complete with success.

Jesse Kempa Altera Corp. jkempa at altera dot com

===== Nios/malloc/free example code =====

#include "excalibur.h"

int main(void) { int i=0, result=0, goodmallocs=0; unsigned char *buff; for(i=0; i< 1030; i++) { buff = (unsigned char *) malloc(1024); if(buff) goodmallocs++; else printf("error mallocing at i=%d\n", i); free(buff); } printf("I was able to malloc() %d 1024-byte blocks. Bye.\n", goodmallocs); return 0; }

=========================

Reply to
Jesse Kempa

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.