Dynamic Memory Alloc in additional RAM Banks

09 Dec 2012

Hi, In the current revision of the compiler, is it possible to allocate memory dynamically in the additional RAM Banks?

I know that the initial accessor variable for these banks would have to be global static. Using "placement new" however it is possible to allocate memory starting from a specific memory location.

The main question could be answered by the following two specific sub-questions:-

i) Is there a mechanism wherein, if a given additional bank is full then it automatically uses any free space available in the main RAM? If heap allocation is not possible for additional RAMS and the code still points to a memory alloc inside these banks then how is it handled internally?

ii) This question is in relation to the main theme of the question. I have read quite a few topics/threads around and they talk about codes/scripts that exist to measure available RAM at any given point of time. I think it is a tool which would help anyone greatly, especially knowing how much STACK/HEAP remains. I saw the python script posted by Igor which talks about the main RAM. Are there other similar Show Memory kind of codes which exist?

11 Dec 2012

Anyone, any idea regarding this? Admins?

14 Dec 2012

It's a question specific to the LPC 1768. Anyone have any idea? How does the runtime system handle this? Please read the first question in the thread.

15 Dec 2012

I'm re-kindling this thread. How do I get this to the attention of the admins? It's pretty urgent that I know how the mbed works exactly as far as dynamic alloc goes. It's a general mbed question that greatly influences my application.

15 Dec 2012

Simon Ford - Tagging you, need help here

04 Jan 2013

Noone seems to reply to this thread. I hope there isn't an issue of visibility. I'm bringing this thread alive again because I think this is a relevant thread for quite a few ppl who face memory issues.

04 Jan 2013

My guess is that most of the mbed users have quite a clear notion of the memory restrictions, after all it is 'only' 64k. On multimegabyte systems with virtual memory this is quite another thing.

You can create a second heap system in the second 32k block but not if you want to use ethernet or USB...

04 Jan 2013

Can you elaborate on creating a second heap system? Does that mean it isn't natively provided and dynamically allocation isn't possible? Assume Ethernet and USB et al are not used whatsoever.

04 Jan 2013

I'd be surprised if there is an existing transparent mechanism for using both heaps for general-purpose automatic dynamic allocation. Most MCUs do not have RAM split in this way, the two blocks of RAM are not contiguous, and - as Gert pointed out you can't use the second 32K block if is already being used by other MCU functions.

We recently tackled this problem in Astrobe (our Oberon language development system) by adding some new features in the v4.3 release. These are described in the three sections with the following headings in "What's New in Astrobe for Cortex M3":

  • Oberon Language Extensions and Features: DISPOSE
  • IDE Features: Link Options
  • New Library Modules: Storage

http://www.astrobe.com/WhatsNewM3.htm

While it will not directly help you if you are using a different development system it might trigger a few ideas of how you can approach the problem that you are trying to solve.

Alternatively if you can describe the problem you are trying to solve rather than asking general 'leading' questions you might getting a more useful response. e.g. if you just want to use a large block of RAM for additional buffer storage the solution will be a lot more straightforward than if you want to use it to store an arbitrary collection of varying-sized objects,

HTH, Chris

Chris Burrows CFB Software

05 Jan 2013

Thanks for the reply Chris.

As per your request, my requirement is simply this. The program I am writing involves the use of the Eigen library which basically aids in solving multiple linear eqns via arrays. My arrays are created dynamically. The only way I figured that AHBSRAM0 and AHBSRAM1 were usable as "general RAM" was to allocate them globally and statically right at the beginning of my program.

As mentioned in my original post, I then use the "placement new" operator that takes an argument which looks for that starting address in memory and can allocate dynamically over that memory which has already been allocated(statically at the beginning). Basically, a semblance of memory reuse. After I am done allocating the arrays and solving the linear equations I need to clear that memory and have the entire RAM BANK 0 and 1 implementing circular buffers to store sample values. RAMBANK 0 stores input samples and RAMBANK 1 stores output samples produced by my scheduler(my program is to implement a scheduler for a Synchronous Data Flow Graph(a data structure) which is comprised of producer/consumer nodes with different rates.)

So, basically I need to be able to allocate memory in the additional ram banks(0&1) dynamically and then free them later when I'm done with the Eigen portion of my program. The rest of my main program will use the MAIN 32KB RAM.