简体   繁体   English

object 大小的不同结果?

[英]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谢谢

I did try to replicate your problem with base R object.size function,我确实尝试使用基本 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.似乎没有太大区别,这里和那里可能有 8 个字节,但几乎相同。 I don't think it would make any significant difference in with such a small difference.我不认为在这么小的差异下会有任何显着差异。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM