Subject: [ruby-ffi] Re: Problem with a double** array |
From: mael |
Date: 1/5/10 6:04 AM |
To: ruby-ffi |
Okay, I understood that the offset should be in terms of bytes, and not of the underlying struct, and that there is no reason I have a valid size when retrieving a "naked pointer", but why is the following code triggering a segfault ? def do_clustering article_vectors = get_article_vectors() ncols = article_vectors.size nrows = article_vectors.map{|av|
av.map{|id,tfidf|
id }.max }.max + 1 p_size = FFI.type_size :pointer d_size = FFI.type_size :double data = FFI::MemoryPointer.new :pointer, nrows for i in (0..nrows-1) row_i = FFI::MemoryPointer.new :double, ncols data.put_pointer i*p_size, row_i end for j in (0..ncols-1) col_j = article_vectors[j] col_j.each do|i,tfidf|
c = data.get_pointer i*p_size puts "i=#{i} (nrows=#{nrows}), j=#{j} (ncols=#{ncols}), c = # {c}" c.put_double(j*d_size, tfidf) end end end