Multiple C-Extensions with mkmf

M

Matthew B Gardner

Hello --
I was wondering if there's a way to separate multiple C-extension classes
into separate files but still be able to directly call functions (C-style
calls)? I currently have a bunch of classes in one file for the performance
boost of direct calls over ruby function calls (not Ruby-ish, I know, but the
boost was significant), but the sloppiness isn't very appealing, especially
as the file continues to grow. Hopefully there's a solution that will allow
me to separate the classes without hindering performance?

I appreciate any help,
Matt
 
J

Jeremy Hinegardner

Hi,

Hello --
I was wondering if there's a way to separate multiple C-extension classes
into separate files but still be able to directly call functions (C-style
calls)? I currently have a bunch of classes in one file for the performance
boost of direct calls over ruby function calls (not Ruby-ish, I know, but the
boost was significant), but the sloppiness isn't very appealing, especially
as the file continues to grow. Hopefully there's a solution that will allow
me to separate the classes without hindering performance?

I think we'll probably need some clarification. Do you have 1
extensions that you want to start separating out into multiple .c files?
This is easily done. Just put them all in separate .c files and in the
top level Init_myextname() function call other initialization functions.

I do this in Amalgalite, and I started using this approach after I saw
how the extensions were built for 'rev'. Take a look at those two gems
and see if how their extensions are built help you out.

enjoy,

-jeremy
 
P

Paul Brannan

Hello --
I was wondering if there's a way to separate multiple C-extension classes
into separate files but still be able to directly call functions (C-style
calls)? I currently have a bunch of classes in one file for the performance
boost of direct calls over ruby function calls (not Ruby-ish, I know, but the
boost was significant), but the sloppiness isn't very appealing, especially
as the file continues to grow. Hopefully there's a solution that will allow
me to separate the classes without hindering performance?

Ruby loads extensions with RTLD_GLOBAL, so you should be able to access
exported symbols in another extension if you require that extension
using rb_require().

Paul
 
N

Nobuyoshi Nakada

Hi,

At Thu, 2 Oct 2008 00:41:33 +0900,
Paul Brannan wrote in [ruby-talk:316603]:
Ruby loads extensions with RTLD_GLOBAL, so you should be able to access
exported symbols in another extension if you require that extension
using rb_require().

Don't rely on it, since it's not possible on all platforms.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top