high RAM usage / memory alignment / packing

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I get "region `RAM' overflowed by 712 bytes" on a D10. I have the following arrays:

 

// the arrays
u8   a[288];
u16  b[288];
u16  c[288];
u16  d[16];
// note: these arrays are declared within a few structs

I also have a handful of scalars.

 

I already added "-Wl,--defsym,STACK_SIZE=0x100" to the Linker Flags (in Toolchain -> ARM/GNU Linker -> Miscellaneous).

 

It seems data is always aligned to 4 bytes, which is not ok, not for arrays :)  How do I change that?

This topic has a solution.

Last Edited: Fri. Dec 11, 2015 - 10:01 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For now I resolved this problem through manual bit-packing. I defined a struct with the exact sizes needed:

 

typedef struct my_t
{
    u32 a:8;
    u32 b:12;
    u32 c:12;
} my_t;

And created an array[288] of it. Having bytes and words would be better though.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It also depends on your optimization level. If you have it set -Os then I believe it will also try to pack the data. You can also use...

typedef struct my_t
{
    u8 a;
    u16 b;
    u32 c;
} __attribute__((packed, aligned(1))) my_t;

 

Last Edited: Thu. Dec 10, 2015 - 10:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Chris.

 

That's not very nice to look at or use, but it'll do. I guess IAR or Keil has an advantage here?

 

I found the "-fpack-struct" compiler option, which would resolve the problem globally. But that too didn't work when I tried it, which seems natural because I used arrays.

 

I prefer arrays because they are more accessible while debugging, as the items are progressions in time.

 

FTR: I tried the maximum optimization level, didn't work.

 

Jan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Iar and keil do the same thing. 32 bit aligned accesses are faster. You can specify individual arrays to be packed.
Its easy to gobble up lots of ram compared with an 8bitter.