# Why Base.summarysize show pointers twice?

**URL:** <https://discourse.julialang.org/t/why-base-summarysize-show-pointers-twice/123887>\
**Category:** General Usage\
**Tags:** memory, memory-allocation\
**Created:** [December 16, 2024, 2:19pm UTC](https://discourse.julialang.org/t/why-base-summarysize-show-pointers-twice/123887 "2024-12-16T14:19:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![garazha-ilya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garazha-ilya/32/214384_2.png) [@garazha-ilya](https://discourse.julialang.org/u/garazha-ilya)\
**Post date:** [December 16, 2024, 2:19pm UTC](https://discourse.julialang.org/t/why-base-summarysize-show-pointers-twice/123887/1 "2024-12-16T14:19:47Z")

</div>

Suppose I have string “Moscow”:

```julia
julia> Moscow = "Moscow"
"Moscow"
julia> sizeof(Moscow)
6
julia> Base.summarysize(Moscow)
14

```

I suppose, that 14 = (Pointer to Array of Chars (8 bytes)) + (6 data bytes).

However, when I create a struct:

```julia
julia> struct City
       name::String
       end
julia> Moscow = City("Moscow")
City("Moscow")
julia> Base.summarysize(Moscow)
22

```

Now it has 22 bytes summary size.

I don’t understand where these extra bytes come from. Why is there a new pointer to the string instead of the string itself?

In contrast

```julia
struct Mountain
    first_ascent_year::Int16
    height::UInt16
end
Everest = Mountain(1953,8848)
Base.summarysize(Everest)

```

returns `4`.

```julia
julia> struct Foo
       p1::Ptr
       p2::Ptr
       end

julia> obj = Foo(pointer("123"),pointer("456"))
Foo(Ptr{UInt8} @0x0000018c0f24e190, Ptr{UInt8} @0x0000018c0f24e1c8)

julia> sizeof(obj)
16

julia> Base.summarysize(obj)
32

```

Why are there additional 8 bytes for each non bits type field?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [December 16, 2024, 4:23pm UTC](https://discourse.julialang.org/t/why-base-summarysize-show-pointers-twice/123887/2 "2024-12-16T16:23:21Z")

</div>

As I understand it, each individually allocated object has a “type tag” that precedes the pointer (and data) itself. It’s a bit of internally metadata that’s a part of the total memory usage (`summarysize`) but not really a part of the data itself (`sizeof`).
