Dear julia users/developers,
I decided to ask my questions on the dev forum as they are rather technical in nature and might also foster some discussion on the design of julia arrays. Since the tuple overhaul, types like NTuple{N,Int} are bitstypes and it becomes even more favorable to implement immutable types to store all kinds of arrays / strided data / ... in similar spirit to SubArray; e.g.
immutable StridedData{N,T}
storage::Vector{T}
offset::Int
strides::NTuple{N,Int}
end
In my application, the dimension is stored externally since I am implementing some recursive (divide and conquer) algorithms and the dimensions are sliced all the time. The storage field essentially just indicates the block of memory in which I will be indexing, and therefore only its length is important, which is why I am using Vector{T} instead of Array{N,T} (it might actually originate from on original array with a different number of dimensions).
Now as far as I understand, StridedData can never become a bits type because of the field of type Vector, which essentially is due that a julia Vector supports resize! and push! etc. I've seen in one or more issues that this is a stumble block to further improve e.g. the efficiency of e.g. SubArray, because the pointer to the block of memory cannot be proven to be constant. So I basically have the following questions:
1) Is there a serious penalty from StridedData not being a bits type, e.g. when this is passed around a lot as an argument in a recursive function? Does this imply that e.g. the pointer to the memory will not live on the stack and will have to be read from the heap every time?
2) Is there a better alternative? I could use storage::Ptr{T} since I am only interested in referencing the block of memory, but to then actually read and store data, one needs to use `unsafe_load/store!`, which only work if T is a bits type. Is that correct? Why is this limitation in effect?
3) Was it a wise design choice to give Array{T,1} the resize! functionality, thereby possibly jeopardizing the efficiency of all Array{T,N} objects. I would expect that vectors and multidimensional arrays as mathematical vectors, matrices and tensors which have a constant size throughout there lifetime versus one-dimensional lists that can grow and shrink are two very different use cases and very few programs actually combine the two functionalities, such that maybe these could have been different types. While I agree that this unified behavior is convenient, if this would really be blocking several optimizations for Array{T,N}, then maybe moving the resize! and push! behavior to a separate subtype of AbstractArray{T,1}, called e.g. List{T} or ArrayList{T}, might have been a better choice?