The program may be stored in on chip memory or off chip memory but like any processor, the processor RAM will be on chip. All dynamic memory allocation shall be carried out using this RAM.

How do I know how much RAM I have in my design? I know that we may keep doing malloc and check if memory has run out. However, is there a way to know in advance as to how much total memory there really is?

  • \$\begingroup\$ Typically only "microcontroller" class systems have their primary RAM (that might be used to satisfy a malloc(), etc) on-chip. Anything larger would typically use an off-chip memory for default allocations. In a soft core processor, you have some unique tradeoffs. The obvious question you have to ask is what on-chip and off-chip resources are configured in your particular design, and what does you software stack configure as a heap, and what special mechanisms might exist to allocate from a different pool? \$\endgroup\$ – Chris Stratton Mar 14 '17 at 4:26
  • \$\begingroup\$ All malloc I want should be in on chip memory so it is straightforward to read and allocate and deallocate using standard methods. \$\endgroup\$ – quantum231 Mar 14 '17 at 12:10
  • 1
    \$\begingroup\$ What prevents you from checking the design to find out how much memory you have? Also, dynamic memory doesn't have to be on chip, Nios is perfectly capable to work with off-chip RAM. \$\endgroup\$ – Dmitry Grigoryev Mar 14 '17 at 14:45

You should know this because you built the NOIS processor and had to specify the size of the ram to make the processor. Its whatever you allocated in NIOS, which is stored in a constant in system.h in the BSP generated files.

Malloc will return NULL if it hits the end of the memory space.

| improve this answer | |
  • \$\begingroup\$ The on chip memory will certainly be used for a lot of things. I just want to know how much heap I have for dynamic memory allocation. \$\endgroup\$ – quantum231 Mar 14 '17 at 12:08
  • \$\begingroup\$ Check system.h in the BSP, it will depend on the NIOS II but you will see the memory constants there for size \$\endgroup\$ – Voltage Spike Mar 14 '17 at 15:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.