Ville Sipola wrote in post #995293:
> 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.

I'm afraid that's bound to be the case, given that Floats are not 
immediate values and therefore each one has to be allocated on the heap 
(unless your data happens to have many instances of identical floats, 
and could share the references)

Robert's wrapping sounds like the best way forward, perhaps with some 
memoizing (i.e. lazy creation of Float objects)

It might also help a little if you pre-allocate the array:

a = Array.new(1000000)

For more of a hack, try:

a = Array.new(1000000) { 0.0+0.0 }

Then maybe you could walk the array and overwrite the RFloat structures 
directly (ugh). Note that the 0.0+0.0 frig was required so that the same 
object_id doesn't get used in each element, and that's not guaranteed to 
work in future (e.g. if Ruby did more aggressive constant folding)

-- 
Posted via http://www.ruby-forum.com/.