RubyInline trouble

Hi all,

I am battling with RubyInline to try the following benchmark:

http://pastie.org/1910786

However, it it appears that I am not allowed to define stuff or
initialize an array at the top level in C.

How do I get this to work?

Cheers,

Martin

On Mon, May 16, 2011 at 10:53 AM, Martin H. [email protected] wrote:

Hi all,

I am battling with RubyInline to try the following benchmark:

http://pastie.org/1910786

However, it it appears that I am not allowed to define stuff or
initialize an array at the top level in C.

The #defines do cause the “Can’t find signature” warning. It’s a check
that fails, but RubyInline continues. The real error (‘equal’
undeclared) is because RubyInline is putting your two functions in
separate C files and compiling them independently. You should put them
in the same file by not creating a second ‘builder’ object. Like this:
http://pastie.org/1912520 (see line 84).

Jeff

On May 16, 2011, at 07:53 , Martin H. wrote:

How do I get this to work?
builder.c is ONLY for a C function.

Define static declarations and the like with builder.prefix or
builder.add_static.

ri Inline::C for more info.

This seem to work:

http://pastie.org/1915197

I hope, I build the code the correct way?

Also, the speed increase is roughly 1-fold. I am a bit puzzled that Ruby
on its own is a tad slow on array accession and bit wise operations. But
when is a speed increase big enough to justify moving to Inline C?

Btw, is there a method to pretty print the resulting C code? That would
be nice for inspection.

Morever, I think RubyInline is a bit under documented. The Perl Inline
module comes with a very nice cookbook:

http://search.cpan.org/~sisyphus/Inline-0.48/C/C.pod
http://search.cpan.org/~sisyphus/Inline-0.48/C/C-Cookbook.pod

This RubyInline tool is really cool I must say!

Cheers,

Martin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs