This is a better question for julia-users, since it is a question of usage that may be of more general interest.
unsafe_store!(a,b) is equivalent to setindex!(a,b) is equivalent to a[] = b, which should help you see why the first call doesn't make sense immutable types are immutable, you cannot get around that there was recently an incorrect statement that types must be immutable to be compatible with C. in fact, all types have the same C-like layout. however, isbits types (a subset of immutable types) will be inlined into an Array, whereas a mutable type will not. pointer_to_array takes a pointer and returns an array. Because the number of dimensions is typically small (not 181*361=65000), the function only allows passing tuples of dims. I'm not sure what you are trying to accomplish. On Mon, Mar 17, 2014 at 9:17 PM, Keno Fischer <[email protected]>wrote: > The pointer has to be of the correct type to store the data. I take it you > want to copy the data from that one array into the pointer. You need a > memcpy (probably easiest via an actual ccall to memcpy) for that rather > than an assignment. > > > On Mon, Mar 17, 2014 at 9:14 PM, J Luis <[email protected]> wrote: > >> I am trying to assign an array to immutable type member to later send it >> via a ccall >> >> julia> Mb.data >> Ptr{Float32} @0x0000000000000000 >> >> but (g is a 2D array) >> >> julia> unsafe_store!(Mb.data, reshape(g,181*361)) >> ERROR: no method convert(Type{Float32}, Array{Float32,1}) >> in unsafe_store! at pointer.jl:44 >> >> julia> isbits(Mb.data) >> true >> >> julia> pointer_to_array(Mb.data, reshape(g,181*361)) >> ERROR: no method pointer_to_array(Ptr{Float32}, Array{Float32,1}) >> >> However, the manual when referring to >> unsafe_loader<http://julia.readthedocs.org/en/latest/manual/calling-c-and-fortran-code/#accessing-data-through-a-pointer>says >> >> "Any operation that throws an error is probably currently unimplemented >> and should be posted as a bug so that it can be resolved." >> >> Well, it's throwing an error ... >> >> But if not a valid, is there anyway to accomplish the purpose off >> assigning the an array to that pointer in the immutable type? >> > >
