Interfacing with C executable

J

Joe Van Dyk

Hi,

I have a program in C that is a part of a very complex system. When
the C program is launched, it has access (through shared memory) to a
whole bunch of other information. To communicate via shared memory is
a very complicated process, so, it can only realistically be done in C
(or Ada).

I'd like to access some of the shared memory data in Ruby. I'm
currently doing it through message queues between the Ruby program and
the C program. The C program has a function that's called forty times
a second. In that C function, I check a message queue to see if
there's any messages. If there's a message, I then do a certain
action, based on what the message is. If I need to return data from
the C program to the Ruby program, I add the data to the message queue
from C and then the Ruby program then can access the data.

It's a pretty cumbersome method, as every time I want to access some
different data in Ruby, I gotta update the C program to get and parse
the new request message, get the data from shared memory and return
the new data via message queues to the Ruby program. But it was the
best I could come up with.

Anyone got an idea of how I can improve this?

Thanks,
Joe
 
A

Aredridel

Hi,

I have a program in C that is a part of a very complex system. When
the C program is launched, it has access (through shared memory) to a
whole bunch of other information. To communicate via shared memory is
a very complicated process, so, it can only realistically be done in C
(or Ada).
Anyone got an idea of how I can improve this?

You might try my ruby-packstruct (which lets you define
binary-accurate structures in Ruby, similar to but independent of
ruby/dl) library, and see if you can't do the shared memory interface
yourself. I don't know of any interfaces (haven't looked really) to
the shm functions themselves, but writing one if you're decent in C
shouldn't be hard at all.
 
J

Joe Van Dyk

One way could be creating a socket and communicating through that.

I suppose that might work, but it's still the same concept of me
having to write a custom communication protocol between the two.
 
L

Lyndon Samson

Hi,
...

Anyone got an idea of how I can improve this?

Maybe another C program that dumps the first programs data to some
persistent ( xml/db/rdbms ) format which you can analyse with ruby at
your leisure?
 

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,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top