I need to make a Julia type corresponding to a C struct that has a fixed size array:
struct cstruct {
...
int arr[N] //N known at compile time
...
};
I have defined Julia types corresponding to other C structs with arrays like this:
type jstruct
...
arr::Ptr{Cint}
...
end
But as I understand it, this only works when arr
is a pointer, not an array of a specific size. How can I ensure that the offsets of elements coming after arr
remain the same in both languages?
Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
A fixed array is an array for which the size or length is determined when the array is created and/or allocated. A dynamic array is a random access, variable-size list data structure that allows elements to be added or removed. It is supplied with standard libraries in many modern programming languages.
An Array in Julia can be created with the use of a pre-defined keyword Array() or by simply writing array elements within square brackets([]). There are different ways of creating different types of arrays.
This is usually called with the syntax Type[] . Element values can be specified using Type[a,b,c,...] . zeros([T=Float64,] dims::Tuple) zeros([T=Float64,] dims...) Create an Array , with element type T , of all zeros with size specified by dims .
When you define a C struct with a fixed size array (or with the array hack), the data are stored directly inline within that struct. It's not a pointer to another region. The equivalent Julia structure is:
type JStruct{N}
arr::NTuple{N,Int}
end
That will store the integers directly inline within the struct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With