# Rice 1.3.0 - Now with full 1.9 support!

**URL:** <https://www.ruby-forum.com/t/rice-1-3-0-now-with-full-1-9-support/180207>\
**Category:** Ruby\
**Created:** [December 14, 2009, 7:29pm UTC](https://www.ruby-forum.com/t/rice-1-3-0-now-with-full-1-9-support/180207 "2009-12-14T19:29:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [December 14, 2009, 7:29pm UTC](https://www.ruby-forum.com/t/rice-1-3-0-now-with-full-1-9-support/180207/1 "2009-12-14T19:29:30Z")

</div>

# Rice: Ruby Interface for C++ Extensions

What is Rice?

Rice is a C++ interface to Ruby’s C API. It provides a type-safe and  
exception-safe interface in order to make embedding Ruby and writing  
Ruby extensions with C++ easier. It is similar to Boost.Python in many  
ways, but also attempts to provide an object-oriented interface to all  
of the Ruby C API.

What’s New?

- Full 1.9 support!
- Cleaned up Rice::Director to be easier to use and support  
inheritance  
nicely (see Documentation)
- Multiple Rice extensions pulled into the same Ruby instance now work  
properly

Supported Platforms:

- Linux
- Mac OS X 10.5 and 10.6
- Windows with MinGW / MSYS

What Rice gives you:

- A simple C+±based syntax for wrapping and defining classes
- Automatic conversion of exceptions between C++ and Ruby
- Smart pointers for handling garbage collection
- Wrappers for most builtin types to simplify calling code

Documentation: [http://rice.rubyforge.org](http://rice.rubyforge.org)

Project Page: [GitHub - jameskilton/rice: Account name changed!](http://github.com/jameskilton/rice)

Google G.: [http://groups.google.com/group/ruby-rice](http://groups.google.com/group/ruby-rice)

How do you get Rice?

gem install rice

Note: Rice does require a C++ compiler. See the Documentation page for  
more details.

How simple of a syntax?

wrapper.cpp

#include \<rice/Class.hpp\>  
#include \<rice/Constructor.hpp\>

class MyWrapper {  
public:  
MyWrapper() { }

```
  void doThis() { }
  int doThat(int a, float b) { }

```

};

extern “C”  
void Init\_wrapper()  
{  
define\_class(“MyWrapper”)  
.define\_constructor(Constructor())  
.define\_method(“do\_this”, &MyWrapper::doThis)  
.define\_method(“do\_that”, &MyWrapper::doThat);  
}

extconf.rb

require ‘mkmf-rice’  
create\_makefile(“wrapper”)

test.rb

require ‘wrapper’  
c = MyWrapper.new  
c.do\_this  
c.do\_that(1, 2.0)

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [December 14, 2009, 9:48pm UTC](https://www.ruby-forum.com/t/rice-1-3-0-now-with-full-1-9-support/180207/2 "2009-12-14T21:48:48Z")

</div>

Great news! =)  
(I’m the one who was bugging you about using RB++/Rice for wrapping GSL,  
remember?)

Just a question, how does rice/rb++ handle memory in the GC? I mean,  
does it have a one-to-one mapping between wrapped C pointers and  
objects? Or will it create a new wrapped object (i.e: different  
object\_id) every time a to\_ruby conversion from a wrapped C++ class is  
performed?  
I’m asking this since for my project (not the one with GSL, a 3D+physics  
simulator which is currently wrapped to ruby with SWIG) it may be an  
issue if on every timeframe objects are created and destroyed.

Matt

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [December 14, 2009, 10:56pm UTC](https://www.ruby-forum.com/t/rice-1-3-0-now-with-full-1-9-support/180207/3 "2009-12-14T22:56:08Z")

</div>

On Mon, Dec 14, 2009 at 3:49 PM, Matt B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> simulator which is currently wrapped to ruby with SWIG) it may be an  
> issue if on every timeframe objects are created and destroyed.
> 
> ## Matt
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

AFAIK Rice does a pretty good job of managing object pointers and not  
causing an excessive amount of memory thrashing by creating / destroying  
C++  
and Ruby objects, but I’ve never run any real memory tests against it. I  
do  
know that with my project of wrapping Ogre 3D I have to GC.disable or I  
get  
crashes where memory gets freed before it should (related more to my  
wrapping code than Rice itself, I do believe), so there’s plenty of work  
to  
do with this before it’s rock solid both itself and how people are to  
use  
it.

One thing Rice doesn’t have that I have been asked about is SWIG’s  
%trackobject directive: [SWIG and Ruby](http://www.swig.org/Doc1.3/Ruby.html#Ruby_nn60).  
My  
plan right now is to let the current features get beat on, and for now  
spend  
time on memory management and some work underneath the covers. If you  
find  
some reproducible memory problems do please create an Issue for it, or a  
discussion on the ruby-rice mailing list.

Jason

---

<div class="post-metadata">

**Author:** ![jruyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jruyle](https://www.ruby-forum.com/u/jruyle)\
**Post date:** [December 14, 2009, 11:02pm UTC](https://www.ruby-forum.com/t/rice-1-3-0-now-with-full-1-9-support/180207/4 "2009-12-14T23:02:50Z")

</div>

> One thing Rice doesn’t have that I have been asked about is SWIG’s  
> %trackobject directive: [SWIG and Ruby](http://www.swig.org/Doc1.3/Ruby.html#Ruby_nn60).  
> My  
> plan right now is to let the current features get beat on, and for now  
> spend  
> time on memory management and some work underneath the covers. If you  
> find  
> some reproducible memory problems do please create an Issue for it, or a  
> discussion on the ruby-rice mailing list.

Exactly, in my code I use %trackobjects to do gc\_mark on instances of  
wrapped objects. Therefore it is all working with GC enabled.

In any case, I agree that Rice should settle now, before adding any more  
complicated stuff =) It was just out curiosity that I asked.

Matt
