Skip to content

What does sizeof return? #54007

@LilithHafner

Description

@LilithHafner

From the docstring, for non DataType values,

the size, in bytes, of object obj

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 be sizeof ∘ typeof.

Some examples

julia> sizeof(falses(100))
16

julia> sizeof(fill(false, 100))
100

julia> sizeof("abc")
3

julia> sizeof("aβc")
4

julia> sizeof(['a', 'b', 'c'])
12

julia> sizeof(view(['a', 'b', 'c'], 1:2))
8

julia> sizeof(SubString("aβc", 2))
3

I'd like the answer to this question to appear in help?> sizeof.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsThis change adds or pertains to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions