user14892865
user14892865

Reputation:

different results in object size?

require(lobstr)

x <- lapply(1:50, function(i) c(rep("abc", i)))
  1. obj_size(x) ## 13,352 B

  2. sum(sapply(x, obj_size)) + 50*8 + 56 ## 16104 B 8 is pointer size, 56 is initial space

why the results are different?

thanks

Upvotes: 0

Views: 91

Answers (1)

Anup Tirpude
Anup Tirpude

Reputation: 654

I did try to replicate your problem with base R object.size function,

x <- lapply(1:50, function(i) c(rep("abc", i)))
object.size(x)
sum(sapply(x, object.size)) + 50*8 + 56 

I found below result. there does not seems to be much of a difference here might be 8 bytes here and there but it's nearly the same. I don't think it would make any significant difference in with such a small difference.

enter image description here

Upvotes: 0

Related Questions