dynamic memory allocation NIOS

J

J-Wing

Guest
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?
 
jwing23@hotmail.com (J-Wing) wrote in message news:<d6e7734d.0312302238.3dd6e6ff@posting.google.com>...
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?
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;
}

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

Welcome to EDABoard.com

Sponsor

Back
Top