Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #3557
| From | Ville Sipola <ville_sipola@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Fast way to move C array to ruby (rb_ary_new4)? |
| Date | 2011-04-27 05:46 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <7bb00dec91cd520ed45220d7d899f294@ruby-forum.com> (permalink) |
Good day
I have a number of large arrays in a C module, and I'd need to move them
to ruby as quickly as possible.
Currently I use the following type of an approach:
instance_array_in_ruby = rb_iv_get(calling_class, "@x");
double c_array[1000000];
for(i=0;i<1000000;i++)
{
rb_ary_store(instance_array_in_ruby, i, rb_float_new(c_array[i]));
}
But that's slow, apparently due to the large number of rb_float_new:s.
There is a function called rb_ary_new4 that would seem to fit
the purpose of quickly moving an entire C array to ruby. Only I'm unable
to get it work, as it, too requires VALUE:s.
I've tried many things including mumbo-jumbo like
rb_iv_set(calling_class,"@x",rb_ary_new4(1000000, (VALUE)c_array));, but
I'm only managing to get segfaults or solutions that still need a
million rb_something_new:s.
Would you know an efficient way of moving a large data from C array to
ruby array?
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar | Unroll thread
Fast way to move C array to ruby (rb_ary_new4)? Ville Sipola <ville_sipola@hotmail.com> - 2011-04-27 05:46 -0500
Re: Fast way to move C array to ruby (rb_ary_new4)? Robert Klemme <shortcutter@googlemail.com> - 2011-04-27 07:08 -0500
Re: Fast way to move C array to ruby (rb_ary_new4)? Robert Klemme <shortcutter@googlemail.com> - 2011-04-27 08:06 -0500
Re: Fast way to move C array to ruby (rb_ary_new4)? Cameron McBride <cameron.mcbride@gmail.com> - 2011-04-27 15:02 -0500
Re: Fast way to move C array to ruby (rb_ary_new4)? Ville Sipola <ville_sipola@hotmail.com> - 2011-04-27 17:01 -0500
Re: Fast way to move C array to ruby (rb_ary_new4)? Ville Sipola <ville_sipola@hotmail.com> - 2011-05-06 14:47 -0500
Re: Fast way to move C array to ruby (rb_ary_new4)? Brian Candler <b.candler@pobox.com> - 2011-04-27 11:15 -0500
csiph-web