Skip to content
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

Base.summarysize misses null byte of String #54023

Open
tecosaur opened this issue Apr 10, 2024 · 1 comment
Open

Base.summarysize misses null byte of String #54023

tecosaur opened this issue Apr 10, 2024 · 1 comment

Comments

@tecosaur
Copy link
Contributor

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?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Apr 10, 2024

It also doesn't include padding bytes in the allocator. I guess we should account for the null here though, in case someone is trying to expand their alloc request to fill that padding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants