On 1/16/2009 12:46 PM, Gabriel Margarido wrote:> Hello everyone,
>
> I have the following issue: one function generates a very big array (can be
> more than 1 Gb) and returns a few variables, including this big one. Memory
> allocation is OK while the function is running, but the final steps make
> some copies that can be problematic. I looked for a way to return the
values
> without copying (even tried Rmemprof), but without success. Any ideas?
> The code looks like this:
>
> myfunc <- function() {
> ...
> bigarray <- ...
> ...
> final <- list(..., bigarray=bigarray, ...)
> class(final) <- "myfunc"
> final
> }
>
> Thank you in advance,
I believe this will do less copying, but I haven't profiled it to be
sure. Replace the last three lines with this one statement:
structure(list(..., bigarray=bigarray, ...),
class = "myfunc")
If that doesn't help, then you really need to determine where the
copying is happening: you can use Rprofmem() to do that.
Duncan Murdoch