You'll see why if you type `methods(mmap_array)`: the dims has to be 
represented as a tuple.

Currently, the only way I know of to create a fixed-sized buffer as an element 
of a "struct" in julia is via immutables with one field per object. Here's one 
example:
https://github.com/JuliaGPU/CUDArt.jl/blob/1742a19b35a52ecec4ee14cfbec823f8bcb22e0f/gen/gen_libcudart_h.jl#L403-L660

It has not escaped notice that this is less than ideal :-).

--Tim

On Friday, November 21, 2014 11:57:10 AM Joshua Adelman wrote:
> 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

Reply via email to