search for: r_preserveobject

Displaying 20 results from an estimated 21 matches for "r_preserveobject".

2010 Jan 02
1
R_PreserveObject, R_ReleaseObject : reference counting needed ?
Hello, We are currently making lots of changes to Rcpp (see the open Rcpp mailing list if interested [1] in the details). We are now using [2] R_PreserveObject and R_ReleaseObject to manage garbage collection instead of the PROTECT/UNPROTECT dance. This seems to work well, but I was wondering if there was documentation about it. In particular, if we preserve the same SEXP twice (or more), should we implement some sort of reference counting ? Reading...
2008 Feb 22
1
Calling R_PreserveObject from embedded R
...lk. I've followed up the examples of the documentation showing how to run R embedded, and I got it partially working. However, I have a problem with the reference handling of the R objects. I've followed this strategy: every time I call a function in R and it answers me a SEXP, I called R_PreserveObject(sexp), and wrap it with a Smalltalk object. Whenever the Smalltalk object dies, I release the R object by calling R_ReleaseObject(sexp). This seems to handle well the life cycle, but makes the running process to use a growing and a never ending amount of memory. Actually, after experimenting a...
2014 Mar 06
2
A question about multiple(?) out of order ReleaseObject
Hello, This is a question that probably reveals my lack of understanding. In a C function (call it cfunc), i created a SEXP, called S, and then called R_PreserveObject on S. I returned the SEXP to the calling R function (call it rfunc). Note, I didn't call R_ReleaseObject on S. v <- .Call("cfunc") So, are the following statements correct 1. S is 'doubly' protected from the GC by being associated both with 'v' and because it...
2010 Jan 02
3
R-devel Digest, Vol 83, Issue 2
...g the R source, others will correct where deemed necessary] On 1/2/10 12:00 PM, r-devel-request at r-project.org wrote: > > Hello, > > We are currently making lots of changes to Rcpp (see the open Rcpp > mailing list if interested [1] in the details). > > We are now using [2] R_PreserveObject and R_ReleaseObject to manage > garbage collection instead of the PROTECT/UNPROTECT dance. This seems to > work well, but I was wondering if there was documentation about it. The most precise technical documentation is in memory.c PROTECT is an alias for Rf_protect, itself an alias for SEXP...
2005 Apr 12
5
How allocate STRSXP outside of gc
Hi, I am trying to figure a way to allocate a string SEXP so that gc() won't ever collect it. Here is a little bit of a background. Suppose I want to write a .Call-callable function that upon each call returns the same value, say mkChar("foo"): SEXP getFoo() { return mkChar("foo"); } The above implementation doesn't take advantage of the fact that
2003 Aug 24
1
declarations in non-exported headers and embedding R
...ARSE_NULL 0 #define PARSE_OK 1 #define PARSE_INCOMPLETE 2 #define PARSE_ERROR 3 #define PARSE_EOF 4 ----------------------------------------------------------- From non-exported header file ${R_HOME}/src/include/Defn.h ----------------------------------------------------------- extern void R_PreserveObject(SEXP); extern void R_ReleaseObject(SEXP); Use: ------------- The first time a PL/R function is called, the R function is built and parsed using R_ParseVector(), then cached for subsequent calls. Without R_PreserveObject() garbage collection destroys the object while PL/R is still trying to use...
2014 Mar 07
0
Repost: (apologies for HTML post) A question about multiple(?) out of order ReleaseObject
Apologies, I am resending this because my emails seem to go in HTML form. Hello, This is a question that probably reveals my lack of understanding. In a C function (call it cfunc), i created a SEXP, called S, and then called R_PreserveObject on S. I returned the SEXP to the calling R function (call it rfunc). Note, I didn't call R_ReleaseObject on S. v <- .Call("cfunc") So, are the following statements correct 1. S is 'doubly' protected from the GC by being associated both with 'v' and because it...
2014 Mar 07
0
Many apologies: last post: A question about multiple(?) out of order ReleaseObject
Apologies, I am resending this because my emails seem to go in HTML form. (I haven't as yet figured gmail web interface) Hello, This is a question that probably reveals my lack of understanding. In a C function (call it cfunc), i created a SEXP, called S, and then called R_PreserveObject on S. I returned the SEXP to the calling R function (call it rfunc). Note, I didn't call R_ReleaseObject on S. v <- .Call("cfunc") So, are the following statements correct 1. S is 'doubly' protected from the GC by being associated both with 'v' and because it...
2008 Jul 20
1
garbage collection, "preserved" variables, and different outcome depending on "--verbose" or not
...Object(void) { SEXP x_R; int len_x = 1000000; PROTECT(x_R = allocVector(REALSXP, len_x)); Rprintf("Created 'x' at %p\n", x_R); Rprintf(" (mode is %i, length is %i)\n", TYPEOF(x_R), LENGTH(x_R)); Rprintf(" (first element is %d)\n", REAL(x_R)[0]); R_PreserveObject(x_R); UNPROTECT(1); return x_R; } void printObject(SEXP sexp) { Rprintf("object at %p\n", sexp); Rprintf(" (mode is %i, length is %i, named is %i)\n", TYPEOF(sexp), LENGTH(sexp), NAMED(sexp)); } SEXP lostobject(SEXP n_R) { /* * This function will: * 1- crea...
2005 Sep 18
0
Updated rawConnection() patch
...@@ -1795,6 +1822,17 @@ free(this->lastline); free(this); } +static void outtext_grow(Routtextconn this, int need) +{ + SEXP tmp = this->data; + int len = length(tmp); + if (this->len + need > len) { + this->data = lengthgets(tmp, len + need + (len>>3) + 16); + R_PreserveObject(this->data); + R_ReleaseObject(tmp); + } +} + #define LAST_LINE_LEN 256 static int text_vfprintf(Rconnection con, const char *format, va_list ap) @@ -1803,7 +1841,6 @@ char buf[BUFSIZE], *b = buf, *p, *q, *vmax = vmaxget(); int res = 0, usedRalloc = FALSE, buffree, already = s...
2005 Aug 17
2
About R variable references
Hello Group, I could use an advice on how SEXP handles work. My aim is to implement a system where I initially set a few global variables that are used for communication between C and R code. Then I do some work with R code and periodically call a function of my own that will update the system state. Such a design is useful for many purposes (for GUIs to name one). I am not entirely sure that R
2002 Jan 02
1
Building R-1.4 on Tru64
...tch.o method_meta_data.o slot.o -L/usr/local/lib /usr/ucb/ld: Warning: Unresolved: TYPEOF Rf_error Rf_protect Rf_substitute Rf_unprotect Rf_duplicate Rf_VectorToPairList R_NilValue Rf_NewEnvironment R_set_standardGeneric_ptr R_GlobalEnv R_set_quick_method_check Rf_install Rf_allocVector LOGICAL R_PreserveObject Rf_mkChar SET_STRING_ELT Rf_findVar R_UnboundValue VECTOR_ELT R_NamesSymbol Rf_getAttrib Rf_length STRING_ELT R_CHAR R_do_slot Rf_asChar PRINTNAME Rf_isNull CAR CDR R_data_class Rf_isFunction Rf_findFun SETCAR Rf_eval INTEGER CLOENV Rf_findVarInFrame Rf_isSymbol ENCLOS SYMVALUE Rf_asLogical R_Missi...
2009 Nov 30
1
:Re: PROTECT and OCaml GC.
>>> On Nov 28, 2009, at 7:50 PM, Guillaume Yziquel wrote: >>> >>> FWIW what I think you should be really looking at is >>> R_PreserveObject/R_ReleaseObject. > > OK. Thanks. >>> I would suggest looking at the many other R embeddings in other >>> languages that already exist since I don't think you approach is >>> very viable (but I think I expressed that already before). > > Lisp - the only t...
2012 Nov 15
1
bug with mapply() on an S4 object
Hi, Starting with ordinary vectors, so we know what to expect: > mapply(function(x, y) {x * y}, 101:106, rep(1:3, 2)) [1] 101 204 309 104 210 318 > mapply(function(x, y) {x * y}, 101:106, 1:3) [1] 101 204 309 104 210 318 Now with an S4 object: setClass("A", representation(aa="integer")) a <- new("A", aa=101:106) > length(a)
2024 Apr 25
1
Big speedup in install.packages() by re-using connections
I'd like to raise this again now that 4.4 is out. Below is a more complete patch which includes a function to properly cleanup libcurl when R quits. Implementing this is a little tricky because libcurl is a separate "module" in R, perhaps there is a better way, but this works: view: https://github.com/r-devel/r-svn/pull/166/files patch:
2009 Jan 08
1
Callbacks seems to get GCed.
Dear list, I am trying to implement a publish-subscribe mechanism in for an embedded R interpreter. But somehow my registered closures seem to get collected by the GC, even though I have protected them. I have reducted my code to the following sample. Sorry if it is a little verbose. The first couple of call of calls still work, but at some point one of the callbacks (callback1 in my
2014 Mar 05
1
[PATCH] Code coverage support proof of concept
...+ R_Cov_freqs_hash = R_NewHashedEnv(R_NilValue, ScalarInteger(0)); + PROTECT(sexp = ScalarInteger(nb_lines)); + defineVar(install(".nb_lines"), sexp, R_Cov_freqs_hash); + + PROTECT(sexp = ScalarReal(growth_rate)); + defineVar(install(".growth_rate"), sexp, R_Cov_freqs_hash); + + R_PreserveObject(R_Cov_freqs_hash); +} + +/* Ends the code coverage tracing. + * and returns an environment with symbols named after the covered source files and values + * matrices of dim n*2, which first column is the line number and the second the nb of occurrences + */ +SEXP do_Rcov_stop(void) +{ + SEXP names,...
2008 May 07
1
[BioC] RCurl loading problem with 64 bit linux distribution
...U R_CHAR U R_ClassSymbol U R_ExternalPtrAddr U R_ExternalPtrTag U R_GlobalEnv U R_MakeExternalPtr U R_NaInt U R_NamesSymbol U R_NilValue U R_PreserveObject U R_RegisterCFinalizer U R_ReleaseObject U R_alloc 0000000000003a90 T R_base64_decode 0000000000003910 T R_base64_encode 0000000000005060 T R_call_R_write_function 0000000000003bc0 T R_check_bits 00000000000047f0 T R_curlMultiPerform 0000000000004d...
2008 May 07
1
[BioC] RCurl loading problem with 64 bit linux distribution
...U R_CHAR U R_ClassSymbol U R_ExternalPtrAddr U R_ExternalPtrTag U R_GlobalEnv U R_MakeExternalPtr U R_NaInt U R_NamesSymbol U R_NilValue U R_PreserveObject U R_RegisterCFinalizer U R_ReleaseObject U R_alloc 0000000000003a90 T R_base64_decode 0000000000003910 T R_base64_encode 0000000000005060 T R_call_R_write_function 0000000000003bc0 T R_check_bits 00000000000047f0 T R_curlMultiPerform 0000000000004d...
2005 Aug 22
2
RFC: "loop connections"
...on] = newloop(desc, stext); + } else if (strncmp(open, "w", 1) == 0 || strncmp(open, "a", 1) == 0) { + if(!isString(stext)) + error(_("invalid 'object' argument")); if (OutTextData == NULL) { OutTextData = allocVector(VECSXP, NCONNECTIONS); R_PreserveObject(OutTextData); } SET_VECTOR_ELT(OutTextData, ncon, venv); con = Connections[ncon] = - newouttext(CHAR(STRING_ELT(stext, 0)), sfile, open, ncon); + newoutloop(CHAR(STRING_ELT(stext, 0)), sfile, open, ncon); } else errorcall(call, _("unsupported mode")); @@ -1942,7...