RubyInline trouble

M

Martin Hansen

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
 
J

Jeff Dallien

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
 
R

Ryan Davis

Hi all,
=20
=20
I am battling with RubyInline to try the following benchmark:
=20
http://pastie.org/1910786
=20
However, it it appears that I am not allowed to define stuff or
initialize an array at the top level in C.
=20
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.
 
M

Martin Hansen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top