Implementation Details of Vector (or Array in General) and String

Im currently searching through the Julia Code of both Vector/Array and String, but so far I haven’t found any details on how these are actually structured at a low level.

From using Base.summarysize, I can guess that Vector uses 40 Bytes to store Information such as length, a pointer and capacity (like a lot of C++ Vector implementations do), and that String uses 8 Bytes + the length of the UTF-8 String, but I’m interested in where in the Code these are implemented. My Guess would be somewhere in the C/C++ Part of Julia, but I am unsure where exactly to search there.

Example of using Base.summarysize:

sizeof(collect(1:100))
800

julia> Base.summarysize(collect(1:100))
840

julia> Base.summarysize([])
40

julia> Base.summarysize("")
8

julia> Base.summarysize("Hello World!")
20

julia> Base.summarysize("A")
9

julia> Base.summarysize("Ä")
10

The array type is defined here:

https://github.com/JuliaLang/julia/blob/7005b7d68be7e6dddb6fba70de855df0abdf3c22/src/julia.h#L177

Most of the functionality is implemented in src/array.c:

https://github.com/JuliaLang/julia/blob/master/src/array.c

6 Likes