c - Is this structure too large? -


the structure speaking of last one. segmentation faults when try use it, , when use sizeof size 218369176 returned.

typedef struct { unsigned long       a1; /* last structure in group. */ unsigned long       a2; /* next structure in group. */ char            rc; /* representing character. */ short           st; /* type of structure (purpose). */ short           pl; /* privilege level required alter. */ short           vt; /* type of value (short, char, int, long, float, double, void*). */ union {     short       s;     char        c;     int     i;     long        l;     float       f;     double      d;     void*       p; }           un; /* union containing values stored. */ } index_struct;             /* structure composing table tree. */  typedef struct { unsigned long       sr;                             /* script return value. */ unsigned long       ir;                             /* interpreter return value. */ unsigned long       lc;                             /* execution counter (text division interpreter stopped at). */ short           ai;                             /* action identifier (current status of interpretation). */ short           pr;                             /* script privilege information. */ char            st[65536 /* change script_text_size this. */];     /* segment containing script text. */ index_struct        lt[65536 /* change local_tree_size this. */];      /* segment containing local tree. */ } script_struct;                                        /* structure containing script state information , variables. */  typedef struct { unsigned long       us;                         /* number of unjoined scripts. */ unsigned long       sn;                         /* number of running scripts. */ short           es;                         /* environment status. */ script_struct       sl[100 /* change max_number_scripts this. */]; /* segment containing script list. */ index_struct        gt[65536 /* change global_tree_size this. */]; /* segment containing global tree. */ } environment_struct; 

edit: popular request, here entire source code file.

/*  * by:  charles edwin swain 3rd.  * languages:  c , (if ever comment out sections of code) x86 assembly.  */  #include <stdio.h>  /* #include <stdint.h>  const uint8_t cpuid_unspecified = 0; const uint8_t cpuid_supported = 1; const uint8_t cpuid_unsupported = 2;  typedef struct {     uint32_t    maximum_standard_level;     uint32_t    raw_vendorid[4];     uint32_t    raw_processortypeorfamilyormodelorstepping;     uint32_t    num_extendedfamily;     uint32_t    num_extendedmodel;     uint32_t    num_type;     uint32_t    num_family;     uint32_t         uint32_t    raw_brandidorcluflushorcpucountorapicid;     uint32_t    raw_featureflags_a;     uint32_t    raw_featureflags_b;     uint8_t features[64]; } cpuid_struct; */  /* these constants associated hard coded limits, , must same ensure proper functionality. */ const unsigned long script_text_size    = 65536;    /* size of segment containing script text. */ const unsigned long global_tree_size    = 65536;    /* size of segment composing global tree. */ const unsigned long local_tree_size = 65536;    /* size of segments composing local trees. */ const unsigned long max_number_scripts  = 100;      /* maximum number of running scripts in environment. */  typedef struct {     unsigned long       a1; /* last structure in group. */     unsigned long       a2; /* next structure in group. */     char            rc; /* representing character. */     short           st; /* type of structure (purpose). */     short           pl; /* privilege level required alter. */     short           vt; /* type of value (short, char, int, long, float, double, void*). */     union     {         short       s;         char        c;         int     i;         long        l;         float       f;         double      d;         void*       p;     }           un; /* union containing values stored. */ } index_struct;             /* structure composing table tree. */  typedef struct {     unsigned long       sr;                             /* script return value. */     unsigned long       ir;                             /* interpreter return value. */     unsigned long       lc;                             /* execution counter (text division interpreter stopped at). */     short           ai;                             /* action identifier (current status of interpretation). */     short           pr;                             /* script privilege information. */     char            st[65536 /* change script_text_size this. */];     /* segment containing script text. */     index_struct        lt[65536 /* change local_tree_size this. */];      /* segment containing local tree. */ } script_struct;                                        /* structure containing script state information , variables. */  typedef struct {     unsigned long       us;                         /* number of unjoined scripts. */     unsigned long       sn;                         /* number of running scripts. */     short           es;                         /* environment status. */     script_struct       sl[100 /* change max_number_scripts this. */]; /* segment containing script list. */     index_struct        gt[65536 /* change global_tree_size this. */]; /* segment containing global tree. */ } environment_struct;                                   /* structure containing environment state information , global tree. */  /*  * function definition , calling conventions follow:  *  *  - non-interpreter functions should called through wrapper function.  *  - wrapper function's address specified through p field of index_struct in global tree.  *  - return items of function specified through global tree, under 'f_retu'.  *  - arguments function specified through global tree, under 'f_argv'.  *  - number of arguments function specified through global tree, under 'f_argc'.  *  - before calling wrapper function, these fields , environment status appropriately set.  *  - wrapper function takes pointer segment containing global tree argument (outside interpreter).  *  - wrapper function sorts through arguments , calls appropriate function wrapping.  *  - once function returns, sets actual interpreter buffers accordingly.  *  - meant above wrapper function use temporary buffers in call function, transfer data on according global tree arguments.  *  - once wrapper function returns, calling (interpreter) code should copy data return appropriate location , wipe involved tables (for security).  *  - entire state uninterruptable interruption code moment interpreter begins call after interpreter finishes wiping data.  *  - above not include signals, , describes regard interpreter auto returning after interpreting input.  *  */  /* creates fresh interpreter environment. */ int ecreate(environment_struct* environment) {     if (environment == null)     {         return -1;     }     else     {         if (environment->es != 0)         {             return -2;         }         else         {             environment->us = 0;             environment->sn = 0;             environment->es = 1;             return 0;         }     } }  /* cleans , shuts down interpreter environment. */ int edestroy(environment_struct* environment) {     if (environment == null)     {         return -1;     }     else     {         if (environment->es == 0)         {             return -2;         }         else         {             environment_struct environment_b;             *environment = environment_b;             return 0;         }     } }  /* main function. */ int main(int argc, char** argv) { /* sizeof is.  works fine when code behind next comment not commented in.*/     printf("%lu\n", sizeof(environment_struct)); /* next comment. */     environment_struct environment;     int r_ecreate, r_edestroy;     r_ecreate   = ecreate(&environment);     r_edestroy  = edestroy(&environment);     printf("%d, %d\n", r_ecreate, r_edestroy);     return 0; } 

index_struct have size of 24 bytes on average 32-bit system (or 32 bytes on average 64-bit system).

script_struct have size of 1,638,416 bytes (1.6 mb) on average 32-bit system (or 2,162,720 bytes (2.16 mb) on average 64-bit system).

environment_struct have size of 165,414,476 (165.4 mb) on average 32-bit system (or 218,369,176 bytes (218.3 mb) on average 64-bit system (which size you're seeing)).

that insanely large size struct, , might crash system (particularly if use on stack). if allocate several environment_structs (on heap), run out of memory.

so yeah, they're large. waaay large.

edit: yup, you're declaring environment_struct on stack. struct big insane stack.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -