I would like to allocate a large array of a particular type, such that all the data for the array is stored contiguously, i.e., the array stores no pointers.
E.g., suppose I have
type Foo
a::Int64
b::Int64
c::Int8
end
v::Vector{Foo} = Array{Foo}(10000000)
I would like this to effectively allocate 10,000,000 inline Foo objects, such that the actual data for a Foo is stored at v[5] rather than a pointer to a separately allocated Foo. I.e., after the code above, I might just be able to write:
v[5].a=0
v[5].b=0
v[5].c=0
rather than
v[5] = Foo(0, 0, 0)
Is there some way I can achieve this effect? In the worst case, maybe there is an efficient hack I could use where I create my own primitive type and do some bit manipulation to extract a, b, and c. (Of course, that would not be ideal. I’d still be interested in the possibility.)
To be clear, there are 4 things I’m interested in, and would be interested in hearing about progress toward achieving any of them.
- Reducing memory consumption by not storing an array of pointers.
- Reducing memory consumption by allocating many compound types together rather than individually allocating, e.g., 10,000,000 Foos. (This may already happen at various levels by cool Julia internals, but I’m referring to the metadata that must be stored for allocated chunks of memory.)
- Improving efficiency by directly accessing data in the array rather than having to dereference another pointer.
- Maintaining the ability to use convenient syntax like v[5].a while doing the above (but I’d be interested in solutions that don’t allow that syntax too).
Thanks.