-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What does sizeof
return?
#54007
Comments
The whole docstring is this:
Which seems a little confused. The two descriptions here actually seem backwards. In talking about what the size of a type is, it really seems like we shouldn't need to use any of the words "canonical" or "binary" or "representation," do we? It's just the number of bytes needed for the It's when we're talking about the generic behaviors of arbitrary objects where the "canonical binary representation" seems to be both relevant and necessary. To be concrete, I think of Cf. #12791 (comment) |
julia> using Serialization
julia> sizeofs(x) = sizeof(x), length(sprint(serialize, x)), write(devnull, x)
sizeofs (generic function with 1 method)
julia> sizeofs(falses(100))
(16, 61, 16)
julia> sizeofs(fill(false, 100))
(100, 16, 100)
julia> sizeofs("abc")
(3, 13, 3)
julia> sizeofs("aβc")
(4, 13, 4)
julia> sizeofs(['a', 'b', 'c'])
(12, 24, 12)
julia> sizeofs(view(['a', 'b', 'c'], 1:2))
(8, 99, 8)
julia> sizeofs(SubString("aβc", 2))
(3, 37, 3) |
I'm not sure what you're trying to say there, but yes, I initially wrote
:) |
To me, |
I will say that this isn't just a user-level question. @vtjnash and I spent at least an hour trying to figure out what |
My intuition tells me that |
Yeah that would have been very sensible. Unfortunately, |
That's never been the case for (edit: oh, sorry for the duplicate content; I had a stale page and didn't see Oscar's response until I posted) |
Ok, so are there any other exceptions to the intuition I posted above, other than
FWIW, I don't think we'll get around having very low level details mentioned here. The meaning of |
From the docstring, for non DataType values,
There are multiple ways of measuring size:
sizeof ∘ typeof
returns the immediate size of an object (i.e. how many bytes it takes up)Base.summarysize
returns the total amount of referenced memory by an object.sizeof(x)
seems a little different & more domain/semantic specific. The default is Core.sizeof, which is not documented but appears to besizeof ∘ typeof
.Some examples
I'd like the answer to this question to appear in
help?> sizeof
.The text was updated successfully, but these errors were encountered: