5

C/C++ would be good option to write some of the performance critical aspects of a Ruby Application. I know this is possible.

I would like to know how to add C/C++ code into Ruby code; any other language for that matter.

Are there any practical applications of this which you noticed in open source projects or else?

askedJul 14, 2010 at 20:10
rpattabi's user avatar

6 Answers6

9

Besides "Extending Ruby", here are two other resources:

  • README.EXT (extension.rdoc) - shows you more about how to build C extensions. A good compliment to "Extending Ruby"
  • Ruby Inline - This is a library that tries to make it easier to build C extensions by having you call methods in ruby to compile C code.
answeredJul 14, 2010 at 20:22
Adrian's user avatar
Sign up to request clarification or add additional context in comments.

Comments

5

Look in the "Extending Ruby" section of the Pickaxe book:

http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html

answeredJul 14, 2010 at 20:15
peejaybee's user avatar

Comments

4

you should have a look atSWIG - it allows you to create ruby extensions in C/C++.

answeredJul 14, 2010 at 20:14
andyp's user avatar

Comments

2

We useffi in one of our projects.

Ruby-FFI is a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby and JRuby.

It works quite well.

answeredJul 15, 2010 at 14:27
Mark's user avatar

Comments

0

Compile your high performance code into a system service/executable, and call it from inside Ruby...?

answeredJul 14, 2010 at 20:15
danp's user avatar

1 Comment

Sure, system service would be one of the ways. It would be all right for some situations. And probably clumsy to run a system service for small pieces of c++ code in a big algo written in ruby.
0

Seems like you need to read up onExtending Ruby

answeredJul 14, 2010 at 20:17
Peter M's user avatar

1 Comment

Thanks for the suggestion. This is probably one of the first things to study.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.