You can get a pointer to the n-th element of a vector
pointer(v,n). The difference between two consecutive indices gives accordingly the size occupied by one element in the vector. You can then compare that to the actual size of the elements of
v = Vector( [(1., 2., 3.), (4., 5., 6.), (7., 8., 9.)] )
d = Signed(pointer(v,2) - pointer(v,1)) # = 24
d == sizeof(eltype(v)) ? "contiguous" : "non-contiguous or padded"
# prints "contiguous"
If you work with
Array then the above should always hold if
eltype(v) is a bitstype; check with
Base.isbits(eltype(v)). For other element types or
AbstractArray in general, it is not necessarily the case.
v were a
SubArray, you could directly use
Base.iscontiguous(v), which unfortunately is not implemented for plain
s = SubArray( v, (1:3,)) # make a subarray from `v`
Base.iscontiguous(s) # returns true