Hello,

I used to use a (somehow complicated) code in C and I have tried to adapt it
to be called from R without making an excessive amount of changes. I am
afraid I cannot post the code here, but I am going to try to describe the
problem as accurately as possible.

I have some arguments that are most of the cases required for internal C
operations only; but as they are needed a few times as arguments, they are
still passed as arguments. Another argument is a "switch" (with value 0 or
1) that states whether these "arguments" are really needed as arguments or
not. When such switch is 0 (says "no"), the C code "feels free" to
manipulate these "arguments", and in particular it tries to modify its
extension (reallocate).

To be clear:

I define the "argument" in R: values1 <- double(size)
values1 is passed as an argument in ".C".
If the switch is set to 0 (says that "values1" is not a real argument), the
C function tries to reallocate the pseudo-argument values1:

double *tmp2 = realloc(values1, new_size);
        if(tmp2 != NULL){
            values1 = tmp2;
        }
        else{
            Rprintf("\nFATAL ERROR: Could not allocate memory for the
array\n");
            exit(2);
        }

But then, when calling the function ".C", I get *** error for object ...:
pointer being reallocated was not allocated

Is there any workaround for this?

Thank you very much in advance,

David
Can you please Cc to me any replies, just in case I may miss any of them
among the whole amount of emails :-) ?

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to