Skip to content
Prev 56228 / 63424 Next

Objectsize function visiting every element for alt-rep strings

On 1/22/19 6:17 PM, Kevin Ushey wrote:
I don't think one could answer that question at all in the presence of 
sharing (of objects with value semantics due to copy on write, string 
cache or other caches, sharing of objects with referential semantics 
such as environments, etc). Also the mapping from R objects (SEXPs) to 
what users might understand as objects would not be clear (which SEXPs 
belong to which "object", which SEXPs are too low-level for the user to 
be considered, etc). In principle, there could be a memory profiler 
working at SEXP level and exposing all the intricacies of the memory 
layout, answering reachability questions on a heap dump (so one could 
find out about a 1G integer vector and then list all bindings say in 
namespace environments from which it is reachable), but of course that 
would be a lot of work to implement and to maintain. The problem is not 
unique to R (e.g. see Java with the same problems of sharing that 
prevent meaningful definition for object size). I am not persuaded it 
makes sense to add more options to a function that does not have and 
cannot have a well defined user-level semantics, and I would discourage 
writing code that is trying to build on that function as I think that it 
might lead to confusion and frustration. I think equality for example is 
easier to define (just that one could come up with multiple meaningful 
definitions, so it makes sense to have multiple options).

Best
Tomas