[Rd] Setting the names attribute of a list?

Saptarshi Guha saptarshi.guha at gmail.com
Mon Mar 30 03:45:43 CEST 2009


Hello,
I have created a vector with 2 elements(see code below)
I am calling this function many thousands of times (hundreds of
thousands) after some time
i get
 *** caught segfault ***
address 0x5, cause 'memory not mapped'
However, if i dont set the R_NamesSymbol, I do not get any such error.
Am I doing this correctly?

Thank you
Saptarshi

==CODE===

// kxp and usar are two SEXP's which have not been protected
SEXP res
PROTECT(res);
res= allocVector(VECSXP, 2);
SET_VECTOR_ELT(res,0,kxp);
SET_VECTOR_ELT(res,1,usar);

names=allocVector(VECSXP,2);PROTECT(names); //A
SET_VECTOR_ELT(names, 0, mkChar("key")); //A
SET_VECTOR_ELT(names, 1, mkChar("value")); //A
setAttrib(res, R_NamesSymbol,names); //A
UNPROTECT(2);
return(res);


Saptarshi Guha



More information about the R-devel mailing list