Saving memory usage -- .C(....., DUP = FALSE) danger?

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Thu, 26 Nov 1998 14:51:37 +0100


Just found out [R 0.63, standard -v -n] :

    > rm(list=ls())
    > gc()
	     free  total
    Ncells  96538 200000
    Vcells 214008 250000
    > hist(runif(50000))
    Error: heap memory (1953 Kb) exhausted [needed 390 Kb more]

which is a bit astonishing given that I still have room for 214000 double's

    > u1 <- runif(50000)
    > u2 <- runif(50000)
    > gc()
	     free  total
    Ncells  96534 200000
    Vcells 114006 250000

debug(hist.default)  quickly revealed that the error was produced
when  .C("bincount",....) was called.

Looking at the help, 
	help(.C)
and then at the "DUP = TRUE" default argument to .C(.),
I was reminded that every argument is first copied before being passed to
bincount().

Setting the "DUP = FALSE" argument in hist.default
made it work with the above 50000 doubles.

But then I wondered ``more generally'' :

	What exactly happens / can happen when calling, e.g.,

		r <- .C("foo", x=x, y=as.double(y),  DUP = FALSE)

	Will 'x' be altered after the call to .C(*)  if in C's 
		foo(double *x, double *y)
	x is altered?
	Will 'y' be unaltered anyway, since   "as.double(y)" produces a
	a different object than 'y' anway?

I know that I could make experiments and find out,
but hopefully, one of you will know much better and explain to all
R-develers.

Really useful might be a comprehensive list of recommendations 
on when  "DUP = FALSE" is useful / advisable / detestable ...

Thank you!

Martin

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum SOL G1;	Sonneggstr.33
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1086			<><

	
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._