How does Julia store array sizes?

Very simple question, but to my surprise I was unable to find an answer by Googling / searching this forum.

Where/how does Julia internally store size/shape/length information for arrays? I know you just use the size function to get the size of each dimension, but what does this function actually do? I was thinking Arrays might be implemented internally as an (immutable) struct with a buffer containing the raw data, a size field (tuple), and possibly other information. Of course, Arrays are not structs and have no fields. (Perhaps they are internally but this is hidden from view?)

First of all, welcome to our community! :confetti_ball:

I think Julia arrays are implemented in C, not Julia, so they are not structs. As how they implement size, this is an implementation detail, you probably should look at the sources: size calls arraysize that seems to be a C function.


Yes, this is the jl_array_t type defined in C.


Thanks for your explanation pointing out the call to C. I tried looking at the source before, but I could not quite make sense of it due to inexperience with Julia.

1 Like