I'm currently writing a R package for Delaunay and Voronoï tessellations in 3D. Most of the implementation is done in C (with the help of the Qhull library).
While running the Delaunay triangulation on a large number of points (> 10000), I received this error:
Error: protect(): protection stack overflow
In my C code, I run UNPROTECT
at the end of the functions, only one time. I'm wondering: if I split the code in blocks, to run UNPROTECT
multiple times instead of one time (eg each time I reach 1000 PROTECT
), could it change something? Is there a known limit for the number of protections?
I finally removed the PROTECT
s in the for
loops:
PROTECT(R_vertices = allocVector(VECSXP, nsites));
PROTECT(vnames = allocVector(STRSXP, nsites));
nprotect += 2;
for(unsigned i = 0; i < nsites; i++) {
SEXP vertex = SiteSXP(vertices[i], dim);
// SEXP vertex;
// PROTECT(vertex = SiteSXP(vertices[i], dim));
// nprotect++;
SET_VECTOR_ELT(R_vertices, i, vertex);
SET_STRING_ELT(vnames, i, Rf_asChar(VECTOR_ELT(vertex, 0)));
}
setAttrib(R_vertices, R_NamesSymbol, vnames);
It seems they are not necessary. I don't output the vertex
s at the end, I only store them in R_vertices
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.