2

I have the following memory allocation:

unsigned char g1[]={
 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ....0x00 ,0x00 ,0x00 ,0x00 ,0x00 }; 
g2[]={
 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ....0x00 ,0x00 ,0x00 ,0x00 ,0x00 }; 
... 
 unsigned char* index[10] = {g1,g2,g3,g4,g5,g6,g7,g8,g9,g0}; 

This is accessed in the following way:

unsigned char* getMatch(int input){
 return index[input];
}

This is then futher acces using the method of

unsigned char store[1024]
unsigned char* temp = getMatch(n);
for(int i=0;i <50;i++){
 store[i]=temp[i];
}

and store is then modified and send to an external device.

As my program is randomly failing I think it might be running low on SRAM and was wondering if there is any way to force this memory to be placed in flash. Anybody got an idea?

asked Dec 11, 2014 at 13:05

1 Answer 1

5

It's stored in both the FLASH and SRAM because it's initialized array. To store in FLASH only you need use PROGMEM attribute.

const unsigned PROGMEM char g1[]= ...

You cannot access directly but using memcpy_P() function.

answered Dec 11, 2014 at 13:34
2
  • How would I put this in the 2nd array after this? I get a lot of error: invalid conversion from ‘const unsigned char*’ to ‘unsigned char* errors. Commented Dec 11, 2014 at 13:39
  • Never mind got it. Commented Dec 11, 2014 at 15:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.