From: ara.t.howard@... Date: 2006-12-13T09:04:16+09:00 Subject: Re: C => Ruby plus TCP serialization using Marshal.dump/load On Wed, 13 Dec 2006, Tim Pease wrote: > On 12/12/06, ara.t.howard@noaa.gov wrote: >> On Wed, 13 Dec 2006, Nathan Baker wrote: >> >> > Hey, >> > >> > We are writing an application that gets data from a C library, passes >> > it through our Ruby framework and over the network, and then sends >> > those data back down into the C library. We don't actually want to >> > manipulate the data in Ruby, but we do want to be able to store them in >> > an opaque blob and have them marshal correctly and arrive intact. It is >> > also worth noting that we are trying to produce a generic framework, so >> > we want to make no assumptions about the sort of data we might be >> > getting from C. >> > >> > What is the best way to do this? We tried the naive approach, using >> > Data_Wrap_Struct to pass the data into Ruby and then Data_Get_Struct to >> > move the data back down to C, but then when we tried to serialize it >> > using Marshal.dump, it failed (no marshal_dump is defined for class >> > Object). >> > >> > Is there a relatively painless way to wrap data and pass them to Ruby >> > in such a way that these data can then be serialized over the network? >> > >> > Thanks, >> > Nathan >> >> i think you really want to be using mmap. that way there is no 'passing'. >> the interface to mmap is as a string, so joel's comments there apply. mmap >> is >> avialible on nix or windoze. >> > > Hmmm ... are you suggesting that he memory map all the C data to a > file and then send the file over the network to the receiving machine? > > TwP just suggesting using mmap to pass the data between c and ruby using MAP_SHARED. easy from c the, in ruby, you can do string = mmap.to_s socket.write [string.size].pack('N') socket.write string regards. -a -- if you find yourself slandering anybody, first imagine that your mouth is filled with excrement. it will break you of the habit quickly enough. - the dalai lama