Hello everyone,
I have been trying hard to figure out how to attach already-existing double pointers to SEXP vectors in C. The problem I am facing is that I have data that is processed in GPU and results are copied back to host and stored as a row-major matrix (double*). Then, I have a SEXP vector to which I would like to attach each row to without having to copy data from each row individually to new to-be-attached SEXP vectors.
I know that SET_VECTOR_ELT can be used to attach a SEXP vector to another SEXP list. However, since the data coming from the GPU is not stored in SEXP vectors, I wouldn't be able to use SET_VECTOR_ELT unless I do the following:
- create an array of SEXP vectors
- copy the rows coming from the GPU to the corresponding SEXP vectors
- attach each SEXP vector to the final SEXP list using SET_VECTOR_ELT
Though, I am trying to avoid the above solution since it will have a performance penalty due to copying data from one location to another within the memory. Instead, I am looking for something like the following:
- create an array of SEXP vectors
- attach row pointers of the GPU-processed matrix to the corresponding SEXP vectors
- attach each SEXP vector to the final SEXP list using SET_VECTOR_ELT
Any hint will be appreciated.
Thanks a lot
Agree that this isn' the appropriate forum. The other strategy is to allocate the vector in R and fill it elsewhere,
SEXP x = PROTECT(Rf_allocVector(REALSXP, 1000));
/* do something with the memory pointed to by REAL(x) */
UNPROTECT(1);
return x;
@Aaron: Thank you so much. That answers my question.
@Martin: yes I am aware of that. It is just for my purpose, I need a contiguous block of memory that will later be separated to different SEXP object. It now seems that copying to SEXP object is the safest way to go. Thanks for responding :)
I also apologize for posting to the wrong forum. I thought that the tags were sufficient to justify posting the question here!