Method: ProcessShared::ObjectBuffer#put_object
- Defined in:
- lib/process_shared/object_buffer.rb
#put_object(offset, obj) ⇒ Object
Write the serialization of obj
(using Marshal.dump) to this shared memory object at offset
(in bytes).
Raises IndexError if there is insufficient space.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/process_shared/object_buffer.rb', line 11 def put_object(offset, obj) # FIXME: This is a workaround to an issue I'm seeing in # 1.8.7-p352 (not tested in other 1.8's). If I used the code # below that works in 1.9, then inside SharedMemoryIO#write, the # passed string object is 'terminated' (garbage collected?) and # won't respond to any methods... This way is less efficient # since it involves the creation of an intermediate string, but # it works in 1.8.7-p352. if RUBY_VERSION =~ /^1.8/ str = Marshal.dump(obj) return put_bytes(offset, str, 0, str.size) end io = SharedMemoryIO.new(self) io.seek(offset) Marshal.dump(obj, io) end |