I am working on a program and I think i am have issues with memory management. I am doing the work to read a SRAM chip (each position per reading, each position has 8-bit information, read 1024 positions) and store the results into a 2D char array (each row stores one reading result). I would post the whole code but its well over 10k lines and my question is simple *even if its XY
I am not sure if it is correct because the program can not be compiled.
I use bitRead() because the most left-side bit may be 0,
if I use Serial.print(message[index]), it may loss data.
Could you please give me some advice?
Thank you!
Why do you save a textual binary representation of the data?
Do you have a system where a 1k-byte buffer does not hurt?
Your old code even used a 8k-byte buffer...
The data is the initial state of a 32K x 8 SRAM, so the data needs to be stored as a textual binary representation file. Because each position has 8-bits data needs to be stored. If I read 1024 positions, I need 8k-bytes buffer. So I think the 2D char array is necessary. The ATMega 2560 has 8K SRAM, I will reduce the number of reading positions (such as 768 positions) to make sure the SRAM is enough. Thank you!
zhliao:
Because each position has 8-bits data needs to be stored. If I read 1024 positions, I need 8k-bytes buffer. So I think the 2D char array is necessary
Nope.
Each byte contains 8 bits, you only need 1024 byte for a copy and no second dimension.
But you do not have to believe me, I'm no preacher.
Each byte contains 8 bits, you only need 1024 byte for a copy and no second dimension.
But you do not have to believe me, I'm no preacher.
Yes you are right, the space is 1K bytes. So if I define a char array as dataStorge[1024], can I store each 8-bits data as one of the element of this array? I will try it, thank you!
Whandall:
I already posted the code that does exactly that.
Yes, I have tried these two segments of code. The first one seems perfect but when I get such errors in the second void displayInfo( unsigned char message) function:
expected ',' or '...' before 'message'
void displayInfo( unsigned char message){
error: 'message' was not declared in this scope
Serial.print(bitRead(message[index],b));
^
We already defined 'message', why it error happens? Thank you!