Jump to content

Allocating very large arrays


Sauraen
 Share

Recommended Posts

I've been working on the modulation matrix for the SID core of MIDIbox ASIDITY (my project), and I've been adding more and more things as modulation destinations (there's going to be about 1600 of them!) and hence increasing the size of an array storing the outputs of the matrix. All the arrays I've created in the entire core should still fit comfortably in the 64K RAM, with at least 15K left over for the operating system. But this one array is "growing" as I add features, and if I make the change I want to it'll be over 16K.

In the page describing the LPC17 core it says "large arrays have to be assigned to RAM sections in the C code". How do I do this? My code uses only global arrays of fixed size (no memory allocation at runtime, other than local variables within functions, and none of those are arrays), and I know what they all are, so actually I could assign all the arrays in the whole core to memory addresses and make sure they all fit.

Also, I've been allocating global RAM arrays like this:

extern matrix_output outmatrix[NMATRIXOUTPUTS];
And arrays I want to be in flash, not RAM, e.g. frequency lookup tables, like this:
static const u16 sidtemper[128] = { 0, 145, 154, 163, [...], 65535 }; 

Is this correct?

Link to comment
Share on other sites

In the page describing the LPC17 core it says "large arrays have to be assigned to RAM sections in the C code".

Actually it means, that large RAM arrays have to be assigned to the AHB RAM (second half of the 64k RAM) in C code.

This can be done with (example for an u8 array):

u8 __attribute__ ((section (".bss_ahb"))) my_large_array[VERY_HIGH_NUMBER];
Also, I've been allocating global RAM arrays like this:
extern matrix_output outmatrix[NMATRIXOUTPUTS];
the "extern" statement is required when you want to import the symbol into another .c file (therefore you will mostly find "extern" in header files) Actually all variables are "extern" (=global) if you don't explicitely make them local with the "static" attribute.
And arrays I want to be in flash, not RAM, e.g. frequency lookup tables, like this:
static const u16 sidtemper[128] = { 0, 145, 154, 163, [...], 65535 }; 

Is this correct?

yes, "static" makes the variable local, and "const" ensures that it will be located into flash memory.

Best Regards, Thorsten.

Link to comment
Share on other sites

Thank you!

So even though the LPC1769 treats the second 32k block as two 16k blocks, they have contiguous addresses, so I can have an array (in this case about 19k) going between the two?

Also, is there anything else by default (e.g. MIDI input buffers or something) in this 32k that I should leave room for, or can I use it all?

Finally, out of curiosity, where (within the MIOS32 trunk) are these sections defined? I've poked around the source a bit but I haven't seen anything like a memory map. After a bit more poking around, I found etc/ld/LPC17xx/LPC1769.ld . Not that I understand one bit of it... :wink:

Link to comment
Share on other sites

So even though the LPC1769 treats the second 32k block as two 16k blocks, they have contiguous addresses, so I can have an array (in this case about 19k) going between the two?

yes

Also, is there anything else by default (e.g. MIDI input buffers or something) in this 32k that I should leave room for, or can I use it all?

yes - have a look into the project_build/project.sym file, it lists the addresses of all symbols

The RAM section starts at 0x20000000, it's at the bottom of the file

This file is also useful to find out, how much memory is allocated by the variables for the case that you touch the limits again and have to start with optimization measures.

Best Regards, Thorsten.

Link to comment
Share on other sites

Thanks again!

Just one more question about project.sym (which is AWESOME, by the way; I always knew something like this existed somewhere for every program, but actually seeing it in plain text is totally cool!): does the linker always put variables next to each other with no empty space in between? That is, can I find the size of any variable by subtracting its index from the next index above it?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...