search for: r_alloc

Displaying 20 results from an estimated 149 matches for "r_alloc".

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...
2008 Mar 05
1
R_alloc with structures with "flexible array members"
...unsigned int state_count[]; }; To create one such sequence, I allocate storage (following Harbison and Steel) in a C program as follows: struct Sequence *A; int n = 4; A = malloc( sizeof(struct Sequence) + n * sizeof(unsigned int)); If I understand correctly, however, it would be better to use R_alloc instead of malloc (memory automagically freed on exit and error; error-checking). But I do not know how to make the call to R_alloc here, since R_alloc allocates n units of size bytes each. I've tried, without success, the following two: int to_add_for_R_alloc = (int) ceil((float) sizeof...
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] 191481 3063 > length(a)*8 / 2^30 [1] 4.369812 but when I call R_alloc in some of my C code, I get &qu...
2011 Dec 21
1
When exactly do I need R_alloc when using the .Call() interface?
Hi, I am trying to implement an algorithm in C which will be called via the .Call() interface. While reading the 'Writing R Extension' manual, I stumbled upon the R_alloc() function for allocating storage for C objects. The manual says it should be used to allocate storage if an C object is needed/created while manipulating R objects within a function called via the .Call() interface. Because none of the examples in the manual uses R_alloc(), I wonder when it is n...
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 function R_alloc I have a segmentation fault. Changing R_alloc with Calloc and malloc gives the same result. However, in the same shared lib...
2006 Mar 15
1
R_alloc problem on Mac OSX (PR#8683)
Full_Name: Dan Kelley Version: 2.2.1 OS: Mac OSX Submission from: (NULL) (129.173.23.36) I'm having difficulties getting R_alloc() to work on a 64-bit Mac running R 2.2.1 installed via a .dmg file obtained from the R site. Details are given below, in a level of detail that I hope is appropriate. My eye was particularly drawn to line #2 in the gdb 'where' output, but line #1 seems sensible so I may just be displayin...
2006 Mar 13
0
R_alloc problem (Mac OSX)
Hello. I'm having difficulties getting R_alloc() to work. The test platform is a 64-bit Mac running R 2.2.1 installed via a .dmg file obtained from the R site. Details are given below, in a level of detail that I hope is appropriate. My eye was particularly drawn to line #2 in the gdb 'where' output, but line #1 seems sensibl...
2012 May 11
0
[patch] Behavior of .C() and .Fortran() when given double(0) or integer(0) (repost).
...t with other memory-related routines, and more convenient: whereas dereferencing a NULL pointer is an immediate (and therefore easily traced) segfault, dereferencing an invalid pointer that is nevertheless in the general memory area allocated to the program often causes subtle errors down the line; R_alloc asked to allocate 0 bytes returns NULL, at least on my platform; and the C routine can easily check if a pointer is NULL, but with the R-devel behavior, the programmer has to add an explicit way of telling that an empty vector was passed. I've attached a small test case (dotC_NULL.[Rc] files)...
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. In the same shared library, I have a function with this code: partitions=16; ... h2=(long **)R_alloc(partitions,sizeof(long *)...
2008 Aug 12
3
aligned memory allocation in C
...Saito. To get the full power of their code, I want to use their fonction fill_array32 which need aligned memory. That is to say I need to use the C function memalign on windows, posix_memalign on linux and classic malloc on Mac OS. In 'writing R extenstion', they recommand to use R_alloc function to allocate memory in C. Does R_alloc return a pointer to aligned memory? if not how can I do this? probably no, because R crashes when I succesively R_alloc and fill_array32 (cf below) on my macbook with R 2.7.1. Thanks in advance Kind regards Christophe PS : http://www.math.sci....
2008 Aug 12
3
aligned memory allocation in C
...Saito. To get the full power of their code, I want to use their fonction fill_array32 which need aligned memory. That is to say I need to use the C function memalign on windows, posix_memalign on linux and classic malloc on Mac OS. In 'writing R extenstion', they recommand to use R_alloc function to allocate memory in C. Does R_alloc return a pointer to aligned memory? if not how can I do this? probably no, because R crashes when I succesively R_alloc and fill_array32 (cf below) on my macbook with R 2.7.1. Thanks in advance Kind regards Christophe PS : http://www.math.sci....
2004 Dec 30
1
optim/vmmin and R_alloc
I am calling 'vmmin' several times from a C function (which is called via .C). It works very well, except for memory consumption. The cause is that vmmin allocates memory via R_alloc, and this memory is not freed as vmmin exits. Instead all the allocated memory is freed on return of the .C call. In one application, I have 2000 functions of 500 variables each to minimize. In each call to vmmin, about 1MB memory is allocated, which sums up to 2GB in total allocation. I have 2.4...
2010 Apr 19
1
transient memory allocation and external pointers
Hello, The Writing R extensions manual section 6.1.1 describes the transient memory allocation function R_alloc, and states that memory allocated by R_alloc is automatically freed after the .C or .Call function is completed. However, based on my understanding of R's memory handling, as well as some test functions I have written, I suspect that this is not quite accurate. If the .Call function returns a...
2013 Aug 27
1
Error in simulation. NAN
...app_uno_n_j[i] = 1; } int nSamples_save = iter_2; // generatore random GetRNGstate(); // /***************************************** // // UPDATE PARAMETRI // *****************************************/ // alpha double *alpha_acc_P = (double *) R_alloc(1, sizeof(double)); F77_NAME(dcopy)(&incOne, start_alpha_P, &incOne, alpha_acc_P, &incOne); // mu_acc double *mu_acc_P = (double *) R_alloc(J, sizeof(double)); F77_NAME(dcopy)(&incJ, start_mu_P, &incOne, mu_acc_P, &incOne); // phi double *phi_ac...
2008 Apr 11
1
R_alloc vs. malloc
Dear list I have two (trivial) memory-questions related to a call with .C: If I allocate memory with R_alloc in a C-program (called with .C), will that memory "be taken from" the "available memory pool" (of a maximum of 4gb?) which R can allocate? (This is the impression I get from "Writing R extensions".) If instead I use malloc; will that memory then be taken from the ava...
2012 May 04
4
[patch] Behavior of .C() and .Fortran() when given double(0) or integer(0).
...t with other memory-related routines, and more convenient: whereas dereferencing a NULL pointer is an immediate (and therefore easily traced) segfault, dereferencing an invalid pointer that is nevertheless in the general memory area allocated to the program often causes subtle errors down the line; R_alloc asked to allocate 0 bytes returns NULL, at least on my platform; and the C routine can easily check if a pointer is NULL, but with the R-devel behavior, the programmer has to add an explicit way of telling that an empty vector was passed. I've attached a small test case (dotC_NULL.* files) tha...
2005 Jul 19
2
R_AllocatePtr
Had been looking into Luke Tierney's R_AllocatePtr() and was left with a question about exactly when does R reclaim heap memory. Implication of 'simpleref.nw' is that one can allocate C data on the R heap, and as long as pointer object is alive, the data and pointer will remain valid. But it calls allocString() which is implemented us...
1998 Jan 21
2
alloc
...rface (PADI) working with R. The code does some memory allocation and for Splus there is an ifdef which controls whether malloc or S_alloc is called. I did nm R.binary | grep alloc to see if this was supported and I find there are some choices: [2490] | 446036| 272|FUNC |GLOB |0 |7 |R_alloc [806] | 693956| 312|FUNC |LOCL |0 |7 |ReallocString [807] | 693220| 736|FUNC |LOCL |0 |7 |ReallocVector [3444] | 446308| 144|FUNC |GLOB |0 |7 |S_alloc [2429] | 446452| 200|FUNC |GLOB |0 |7 |S_realloc ... [2204] | 1445856| 0|FUNC |G...
2006 Dec 04
2
Library file for the R engine in Windows?
Hi, I am trying to use dynamic memory allocation in the C code to be called by R through the .C interface. I have used R_alloc as explained in the Writing R Extensions and included the R.h header. The program compiles fine but fails when linking. Obviously it needs a library file where R_alloc is found. I have tried to link by adding R.dll to list of files at the end of the link command but that did not work either. The...
2004 Mar 02
1
passing a string from .C()
...omething 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 should probably use R_alloc, e.g. char foo[] = "foo"; *str = R_alloc(sizeof(foo), 1); 2) I don't know if the string pointed to by *str before the re-assignment, which now becomes dangling, will be properly reclaimed. Thanks, Vadim [[alternative HTML version deleted]]