heap - C: how to manage a large structure? -


in c:

i trying use structure containing large array, , have stack overflow error while declaring it. guess (correctly?) don't have enough memory in stack, , therefore, should use heap (i don't want change stack memory size, code used others). show me way simply? or should use else structure?

my code - definitions.h:

#define a_large_number 100000  struct std_calibrations{     double e[a_large_number]; }; 

my code - main.c:

int main(int argc, char *argv[]) {     /* ...     */      // stack overflows here:     struct std_calibrations calibration;      /* ...     */      return (0); }  

thank help!

a couple of options:

  1. use malloc(3) , free(3) dynamically allocate structure @ runtime. option you're talking when "should use heap."

    struct std_calibrations *calibration = malloc(sizeof *calibration); 

    and later,

    free(calibration); 
  2. give structure static storage duration. either add static keyword or make global. option may change semantics how use structure, given example code, should fine.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -