[Rd] allocVector bug ?

From: Vladimir Dergachev <vdergachev_at_rcgardis.com>
Date: Wed 01 Nov 2006 - 22:20:09 GMT

Hi all,

  I was looking at the following piece of code in src/main/memory.c, function allocVector :

    if (size <= NodeClassSize[1]) {

	node_class = 1;
	alloc_size = NodeClassSize[1];


    else {
	node_class = LARGE_NODE_CLASS;
	alloc_size = size;
	for (i = 2; i < NUM_SMALL_NODE_CLASSES; i++) {
	    if (size <= NodeClassSize[i]) {
		node_class = i;
		alloc_size = NodeClassSize[i];


It appears that for LARGE_NODE_CLASS the variable alloc_size should not be size, but something far less as we are not using vector heap, but rather calling malloc directly in the code below (and from discussions I read on this mailing list I think that these two are different - please let me know if I am wrong).

So when allocate a large vector the garbage collector goes nuts trying to find all that space which is not going to be needed after all.

I made an experiment and replaced the line alloc_size=size with alloc_size=0.

R compiled fine (both 2.4.0 and 2.3.1) and passed make check with no issues (it all printed OK).

Furthermore, all allocVector calls completed in no time and my test case run very fast (22 seconds, as opposed to minutes).

In addition, attach() was instantaneous which was wonderful.

Could anyone with deeper knowledge of R internals comment on whether this makes any sense ?

                           thank you very much !

                                        Vladimir Dergachev

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Nov 02 13:53:15 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 03 Nov 2006 - 11:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.