I have been working on a cube timer project for a while and I can't get my variable archived.
I created a uint8_t algorithm [100][40] to store the scrambles, when I try to archive it, the calculator just crashed and cleared the ram.


Code:

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fileioc.h>

void main(void) {
    uint8_t algorithm[100][40];    //this causes ram clear
    ti_var_t historyfile;
    ti_CloseAll();
    historyfile = ti_Open("HIST","w");
    ti_Write(&algorithm, sizeof(uint8_t), sizeof(algorithm)/sizeof(uint8_t), historyfile);
    ti_SetArchiveStatus(true, historyfile);    //this causes ram clear
}

But, when I changed up the size to [100][39], the code works, no crash. Also, size [100][40] works if I don't archive the variable.

Code:

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fileioc.h>

void main(void) {
    uint8_t algorithm[100][39];    //this works
    ti_var_t historyfile;
    ti_CloseAll();
    historyfile = ti_Open("HIST","w");
    ti_Write(&algorithm, sizeof(uint8_t), sizeof(algorithm)/sizeof(uint8_t), historyfile);
    ti_SetArchiveStatus(true, historyfile);    //this works
}

I don't know if [100][40] is too big for ti_setarchivestatus() or if I have done anything wrong, I am pretty new to C. And, it seems like uint8_t [100][39] is the biggest size ti_setarchivestatus() can handle, if I save one more variable, it will also crash. In addition, if I try to save them in seperate files, it still would not work.

Any help is appreciated. Smile
I'm not sure where the stack usually goes and how that relates to other important things in RAM, but you're probably overflowing the stack and clobbering important things by allocating multiple-kilobyte arrays on the stack.

Try giving it static storage duration (better) or dynamically allocating (best).

Code:
uint8_t algorithm[100][40];

void main() { /* ... */ }

Code:
void main() {
    uint8_t (*algorithm)[100][40] = malloc(4000);
    /* ... */
}
The stack is 4KB in size, maximum. 100*40 = 4000 bytes, or 4KB. You should really look at the wiki page that explains this: https://github.com/CE-Programming/toolchain/wiki/Memory-layout

Personally, I would do:


Code:
static uint8_t algorithm[100][40];


Simply add 'static' in front of it so you don't allocate it on the stack.

Dynamic storage is not recommended on the CE if you can avoid it because the malloc() and related routines will add to the size of your program, and the bss simply flows into the heap anyway.
thank you both, it worked
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement