I'm playing around with Julia for the first time in an attempt to see if I
can replace a Python + Cython component of a system I'm building. Basically
I have a file of bytes representing a numpy structured/recarray (in memory
this is an array of structs). This gets memory mapped into a numpy array as
(Python code):
f = open(data_file, 'r+')
cmap = mmap.mmap(f.fileno(), nbytes)
data_array = np.ndarray(size, dtype=dtype, buffer=cmap)
where dtype=[('x', np.int32), ('y', np.float64), ('name', 'S17')].
In cython I would create a C packed struct and to deal with the fixed
length string elements, I would specify them as char[N] arrays:
cdef packed struct atype:
np.int32_t x
np.float64 y
char[17] name
I'm trying to figure out how I would accomplish something similar in Julia.
Setting aside the issue of the fixed length strings for a moment, I thought
to initially create a composite type:
immutable AType
x::Int32
y::Float64
name::???
end
and then if I had an file containing 20 records use:
f = open("test1.dat", "r")
data = mmap_array(AType, 20, f)
but I get an error:
ERROR: `mmap_array` has no method matching mmap_array(::Type{AType},
::Int64, ::IOStream)
Is there a way to memory map a file into an array of custom
records/composite types in Julia? And if there is, how should one represent
the fixed length string fields?
Any suggestions would be much appreciated.
Josh