Re: [julia-users] What is the proper way to allocate and free C struct?

2016-04-17 Thread Andrei Zh
It makes sense. Thanks, once again! For reference, I ended up with code like this: # internal only type XMatrixStruct rows::Cint cols::Cint data::Ptr{Float64} end type XMatrix ptr::Ptr{XMatrixStruct} data::Ptr{Float64} # copied from `unsafe_load(ptr).data` end This way I

Re: [julia-users] What is the proper way to allocate and free C struct?

2016-04-17 Thread Yichao Yu
On Sun, Apr 17, 2016 at 6:23 AM, Andrei Zh wrote: > A followup question. In the above example I'd like to add method `getindex` > for `XMatrix`. Previously, I could do it like this: > > type XMatrix > rows::Cint > cols::Cint > data::Ptr{Float64} > end > >

Re: [julia-users] What is the proper way to allocate and free C struct?

2016-04-17 Thread Andrei Zh
A followup question. In the above example I'd like to add method `getindex` for `XMatrix`. Previously, I could do it like this: type XMatrix rows::Cint cols::Cint data::Ptr{Float64} end getindex(mat::XMatrix, i::Integer) = unsafe_load(mat.data, i) Now after Yichao's suggestion my type

Re: [julia-users] What is the proper way to allocate and free C struct?

2016-04-16 Thread Andrei Zh
This is exactly the answer I hoped to see! Thanks a lot! On Sunday, April 17, 2016 at 2:46:15 AM UTC+3, Yichao Yu wrote: > > On Sat, Apr 16, 2016 at 6:55 PM, Andrei Zh > wrote: > > I have a question regarding Struct Type correspondences section of the > > documentation.

Re: [julia-users] What is the proper way to allocate and free C struct?

2016-04-16 Thread Yichao Yu
On Sat, Apr 16, 2016 at 6:55 PM, Andrei Zh wrote: > I have a question regarding Struct Type correspondences section of the > documentation. Let's say, in a C library we have a struct like this: > > typedef struct { > int rows; > int cols; > double* data; > }