Skip to content
Prev 14538 / 63424 Next

data is getting corrupted

I'm not sure I described the problem correctly with my last post.

The structure that is being allocated contains fixed length arrays and
thus, the location of the strings aren't NULL (the contents are however).

struct SAMPLE_RECORD
{
char            forest[HEADER_CHAR_STR];       /*  forest identifier    */
char            subunit[HEADER_CHAR_STR];      /*  subunit              */
char            stand_name[HEADER_CHAR_STR];   /*  stand name           */
char            legal[HEADER_CHAR_STR];        /*  legal description    */
long            elevation;                     /*  elevation (ft)       */
double          acreage;                       /*  number of acres      */
unsigned long   age;                           /*  stand age            */

unsigned long   sampled_month;     /*  month of the year    */
unsigned long   sampled_day;       /*  day of the month     */
unsigned long   sampled_year;      /*  year measured        */
unsigned long   current_year;      /*  year of forecast     */

double x0;

unsigned long           n_points;
struct PLOT_RECORD      *plots_ptr;

unsigned long           n_plants;
struct PLANT_RECORD     *plants_ptr;
};

The plots_ptr and plants_ptr are set to NULL because they're not static
arrays and are allocated.

Since the problem didn't manifest itself within the strings, but rather in
the arrays that are allocated (plants_ptr) and specifically a single
column (variable) that occurs within the plants_ptr, I still think I have
a problem with the PROTECT/UNPROTECT operations because with small
data.frames (200 rows x 10 cols) the code works fine. With larger
data.frames (2000 rows x 10 cols), then the corruption begins. COuld this
be a problem with the sequencing of the allocate
plants_ptr->PROTECT->assign values to variables->UNPROTECT? Is it possible
to find out when R is performing garbage collection or moving data around?

Thanks,
Jeff.


Duncan Murdoch said: