Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12437 Discussions

Dynamic Memory Allocation in OnChip-Ram

Altera_Forum
Honored Contributor II
1,135 Views

Hello, 

I am looking for a possibility to dynamically allocate memory in OnChip-RAM, 

while heap is in external RAM. 

 

Has anyone experiences regarding this topic?
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
80 Views

Basically no, if You're talking about malloc(). Why not to use direct addressing?

Altera_Forum
Honored Contributor II
80 Views

Yes Socrates, I'm talking about malloc(). 

 

The thing is, that I want to improve the LwIp-Stack and there some structures (e.g. ethernetif, pbuf) allocated dynamically. 

 

As a workaround I did allocate the memory statically, but I think for a better structural design it would be nicer to allocate those structures dynamically at internal RAM. 

 

Maybe a solution could be to reassign the heap to internal RAM, then malloc(), and then put the Heap back to external RAM. But the LwIp malloc-function saves and uses the lowest free block for allocation, which is always in external Ram. 

 

Sure, I know that I could write my own malloc(), but I wanted to know if someone knows an easier or more common way.
Altera_Forum
Honored Contributor II
80 Views

For embedded use it is actually better to avoid malloc() - except maybe at startup. That way you don't suddenly run out of memory in some important code path.

Altera_Forum
Honored Contributor II
80 Views

Or suffer from memory fragmentation. In my experience you have to be VERY careful with dynamic memory allocation in embedded applications.

Reply