CSC/ECE 517 Fall 2010/ch3 3i MM: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 1: Line 1:
= Introduction =
= Introduction =
Ruby is a high-level, [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic programming language] that is useful for everything from short scripting assignments, to entire [http://rubyonrails.org/ web applications] and [[CSC/ECE_517_Fall_2010/ch1_S10_MM desktop GUI applications]].  However, there are inherent downsides in using Ruby come because of its interpreted, dynamic nature.  Using C code for some tasks can improve memory usage, and raw execution speed when compared to Ruby <sup>[http://shootout.alioth.debian.org/]</sup>.
Ruby is a high-level, [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic programming language] that is useful for everything from short scripting assignments, to entire [http://rubyonrails.org/ web applications] and [[CSC/ECE_517_Fall_2010/ch1_S10_MM | desktop GUI applications]].  However, there are inherent downsides in using Ruby come because of its interpreted, dynamic nature.  Using C code for some tasks can improve memory usage, and raw execution speed when compared to Ruby <sup>[http://shootout.alioth.debian.org/]</sup>.


= Using C from Ruby =
= Using C from Ruby =

Revision as of 02:58, 7 October 2010

Introduction

Ruby is a high-level, dynamic programming language that is useful for everything from short scripting assignments, to entire web applications and desktop GUI applications. However, there are inherent downsides in using Ruby come because of its interpreted, dynamic nature. Using C code for some tasks can improve memory usage, and raw execution speed when compared to Ruby [1].

Using C from Ruby

Following are some overviews and examples of ways to create C or C++ extensions to Ruby.

Ruby C API

README.EXT

The README.EXT file contains the latest information and an overview of how to create Ruby extensions in C. It is an invaluable source of information, and is included in any source code distribution of Ruby. The link is to the latest HEAD version in Ruby's official subversion repository, but you may want to read the version that came with your installed version of Ruby.

In Unix-like distributions, for example, this file may be installed installed in '/usr/share/doc/ruby1.8-dev/README.EXT.gz'. To read, from a command prompt type:

> zless /usr/share/doc/ruby1.8-dev/README.EXT.gz

VALUE

...

Example

RubyInline

SWIG

SWIG is a popular wrapper generator that can produce wrappers for C and C++ code in several high level programming languages, including Perl, Python, and Ruby.

Using Ruby from C

README.EXT

Once again, this file, included in the Ruby source code, has a section on using Ruby features from C. Section 2.2 is a brief overview of some techniques for doing this.

Conclusion

References

External Links

RubyInline

Ruby C Extension in Under 5 Minutes

Ruby C Extension Overview