[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Interfacing with C executable

Joe Van Dyk

4/8/2005 11:57:00 PM

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


4 Answers

linus sellberg

4/9/2005 12:07:00 AM

0

Joe Van Dyk wrote:

> Anyone got an idea of how I can improve this?

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

Aredridel

4/9/2005 12:07:00 AM

0

On Apr 8, 2005 5:57 PM, Joe Van Dyk <joevandyk@gmail.com> wrote:
> 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.


Joe Van Dyk

4/9/2005 12:12:00 AM

0

On Apr 8, 2005 5:09 PM, linus sellberg <sellberg@google.com> wrote:
> Joe Van Dyk wrote:
>
> > Anyone got an idea of how I can improve this?
>
> 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.


Lyndon Samson

4/9/2005 5:59:00 AM

0

On Apr 9, 2005 9:57 AM, Joe Van Dyk <joevandyk@gmail.com> wrote:
> 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?



> Thanks,
> Joe
>
>


--
Into RFID? www.rfidnewsupdate.com Simple, fast, news.