Skip to content

Base.summarysize misses null byte of String #54023

@tecosaur

Description

@tecosaur

I've recently been working on my About.jl package, for showing more information about the internals/memory representation of Julia values. When looking into strings a bit more, I came across this bit of jl_alloc_string:

size_t sz = sizeof(size_t) + len + 1; // add space for trailing \nul protector and size

In the REPL, with the 3-codunit string hey, I see this:

julia> ncodeunits("hey")
3

julia> Base.summarysize("hey")
11

Since I'm on a 64-byte system, sizeof(size_t) should be 64-bits/8-bytes, and so 8 + 3 + 1 gives us ... 12, not 11.

It seems like Base.summarysize might be missing the trailing null byte?

Metadata

Metadata

Assignees

No one assigned

    Labels

    observabilitymetrics, timing, understandability, reflection, logging, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions