It is no secret that Ruby sends messages to invoke methods. So it much slower than in C. If you need speed in accessing instance variables and invoking methods you can use CplusRuby:
With CplusRuby you can define custom C structures from within Ruby and wrap them easily in a Ruby class. You can as well define C functions that can access this structure easily. CplusRuby generates setter/getter methods for every property and wrapper methods for the C functions.
The purpose is speed! The C functions can access the C-structure, which is much faster than accessing instance variables. Also, the C functions can call each other directly. This is *much* faster than invoking a method in Ruby. As wrappers are generated, the Ruby-side can access all C-structures and functions as well.
Комментариев нет:
Отправить комментарий