Displaying 20 results from an estimated 5000 matches similar to: "memory allocation and interrupts"
2004 Jun 14
5
mkChar can be interrupted
Hi,
As was discussed earlier in another thread and as documented in R-exts
.Call() should not be interruptible by Ctrl-C. However the following
code, which spends most of its time inside mkChar, turned out to be
interruptible on RH-7.3 R-1.8.1 gcc-2.96:
#include <Rinternals.h>
#include <R.h>
SEXP foo0(const SEXP nSexp) {
int i, n;
SEXP resSexp;
if (!isInteger(nSexp))
2004 Jun 30
2
Slow IO: was [R] naive question
I believe IO in R is slow because of the way it is implemented, not
because it has to do some extra work for the user.
I compared scan() with 'what' argument set (which is, AFAIK, is the
fastest way to read a CSV file) to an equivalent C code. It turned out
to be 20 - 50 times slower.
I can see at least two main reasons why R's IO is so slow (I didn't
profile this though):
A) it
2005 Mar 16
1
function-like macros undefined
Hi,
Somehow function-like macros from Rinternals.h are not defined when I
include the file.
foo.c
##################
#include <R.h>
#include <Rinternals.h>
#ifndef NILSXP
#error("NILSXP")
#endif
#ifndef INTEGER
#error("INTEGER")
#endif
###################
When compiled:
vor/src% gcc -I/usr/local/lib/R/include -g -O2 -c foo.c -o foo.o
foo.c:11:2: #error
2013 Aug 27
1
Error in simulation. NAN
Hi all,
im triyng to implement a bayesian model with R and c++.
I have a strange problem. I can't reproduce the error with a small
script and then i post the original one.
The problem is after the line
for(MCMC_iter2=0;MCMC_iter2<thin;MCMC_iter2++)
For the first 34 iterations all work fine, after, all the simulations
of mu_acc_P return an "nan". If i delete the line
2004 Mar 02
1
passing a string from .C()
Hi,
Could someone please point to an example of passing strings from .C()
calls back to R? I want to be able to do something like this:
str <- .C("return_foo_string", str=character(1))$str
void return_foo_string(char ** str) {
*str = "foo";
}
The above code has at least two memory allocation "concerns":
1) How to properly allocate "foo". I
2003 May 16
1
Reloading a shared library with dyn.load
Hi,
I'm using dyn.load to load a shared library (compiled from C
code) into R. If I dyn.unload it and then dyn.load it again, I
get an hourglass icon in Rgui (R 1.7.0, Win 2000), and it
just sits there forever. I can't press Escape to stop the
current computation, but I can close Rgui without resorting to
using the Task Manager.
Is it a problem with my use of R_alloc? Do I need
2008 Apr 14
1
clean-up actions after non-local exits
Dear R-devel,
Some time ago I started a thread that boiled down to clean-up actions after non-local exits in R, see below. I wonder if there has been any progress on this? R-ext 2.6.1 doesn't say much on the subject.
How, for example, do people deal with a situation where their C (C++) function opens a file and then receives a signal or longjump-s on error(), how do they make sure the
2005 Mar 08
4
how modify object in parent.env
Hi,
Is it possible to modify an object in the parent.env (as opposed to
re-bind)? Here is what I tried:
> x = 1:3
# try to modify the first element of x from within a new environment
> local(get("x", parent.env(environment()))[1] <- NA)
Error in eval(expr, envir, enclos) : Target of assignment expands to
non-language object
# On the other hand retrieval works just fine
>
2008 Jan 19
1
R_alloc segfaults
I want to write a little stand-alone C program that calls R_alloc, but
I get a segmentation fault:
int main(int argc, char** argv){
double* d = (double *)R_alloc(2, sizeof(double)); // <- segmentation fault!
return 0;
}
gdb reveals that sizeof(double) evaluated to 0:
> R_alloc (nelem=2, eltsize=0) at memory.c:1649
so it results in the segfault later.
This is how I compile my
2004 May 01
5
skip lines on a connection
Hi,
I am looking for an efficient way of skipping big chunks of lines on a
connection (not necessarily at the beginning of the file). One way is to
use read lines, e.g. readLines(1e6), but a) this incurs the overhead of
construction of the return char vector and b) has a (fairly remote)
potential to blow up the memory.
Another way would be to use scan(), e.g.
scan(con, skip=1e6, nmax=0)
2003 Sep 03
3
read.table: check.names arg - feature request
Hi,
I thought it would be convenient if the check.names argument to read.table, which currently can only be TRUE/FALSE, could take a function value as well. If the function is supplied it should be used instead of the default make.names.
Here is an example where it can come in handy. I tend to keep my data in coma-separated files with a header line. The header line is prefixed with a comment
2004 Dec 03
4
seq.Date requires by
Hi,
What is the reason for seq.Date to require the 'by' argument and not to
default it to 1 in the example below?
> seq(from=as.Date("1996-01-01"), to=as.Date("1996-12-01"))
Error in seq.Date(from = as.Date("1996-01-01"), to =
as.Date("1996-12-01")) :
exactly two of `to', `by' and `length.out' / `along.with' must be
specified
2004 Jun 08
5
fast mkChar
Hi,
To speed up reading of large (few million lines) CSV files I am writing
custom read functions (in C). By timing various approaches I figured out
that one of the bottlenecks in reading character fields is the mkChar()
function which on each call incurs a lot of garbage-collection-related
overhead.
I wonder if there is a "vectorized" version of mkChar, say mkChar2(char
**, int
2008 Mar 05
1
R_alloc with structures with "flexible array members"
Dear All,
In a package, I want to use some C code where I am using a structure
(as the basic element of a linked list) with flexible array members.
Basically, this is a structure where the last component is an
incomplete array type (e.g., Harbison & Steel, "C, a reference
manual, 5th ed.", p. 159) such as:
struct Sequence {
struct Sequence *next;
int len;
unsigned int
2005 Jun 13
1
memory allocation problem under linux
I have some compiled code that works under winXp but not under linux (kernel
2.6.10-5). I'm also using R 2.1.0
After debugging, I've discovered that in this code:
#define NMAX 256
long **box;
...
box = (long **)R_alloc(NMAX, sizeof(long *)); //<---HERE THE SIGSEGV
for (i=0; i<NMAX; i++) box[i] = (long *) R_alloc(NMAX, sizeof(long));
inside the *first* call to the
2004 Nov 10
3
recursive default argument reference
Hi,
It seems that a formal function argument can not default to an "outer"
variable of the same name:
> x <- "foo"
> ff <- function(x=x) x
> ff()
Error in ff() : recursive default argument reference
>
Is this intentional? Why?
I use R-1.9.1.
Thanks,
Vadim
2005 Mar 10
1
R_alloc with more than 2GB (PR#7721)
Full_Name: Wolfgang Huber
Version: R-devel_2005-03-10
OS: alphaev68-dec-osf4.0f
Submission from: (NULL) (62.253.128.15)
This report concerns allocation of large (>2^31 byte) chunks of memory with
R_alloc. I suspect it is a bug/typo but please don't hate me if it's actually a
feature:
In R, I can happily create large matrices:
> a= matrix(0, nrow=191481, ncol=3063)
> dim(a)
[1]
2005 May 07
4
how to add method to .Primitive function
Hi,
I tried to write the dim method for the list class, but R doesn't seem
to dispatch to it:
> dim.list = function(x) c(length(x[[1]]), length(x))
> dim(list(1))
NULL
> dim.list(list(1))
[1] 1 1
What is the correct way of registering dim.list with .Primitive("dim")?
Thanks,
Vadim
[[alternative HTML version deleted]]
2005 Jun 12
1
memory allocation problem under linux
I have some compiled code that works under winXp but not under linux (kernel
2.6.10-5). I'm also using R 2.1.0
After debugging, I've discovered that this code:
#define NMAX 256
long **box;
...
box = (long **)R_alloc(NMAX, sizeof(long *));
gives a null pointer, so subsequent line:
for (i=0; i<NMAX; i++) box[i] = (long *) R_alloc(NMAX, sizeof(long));
gives a SIGSEGV signal.
2015 Nov 23
4
Custom C finalizers for .Call
WRE explains that R_alloc() can be used to allocate memory which
automatically gets released by R at the end of a .C, .Call or
.External, even in the case of an error or interruption. This is a
really great feature to prevent memory leaks. I was wondering if there
is a way to extend this mechanism to allow for automatically running
UNPROTECT and custom finalizers at the end of a .Call as well.