We are creating a Memory Mapped file in ruby using win32-mmap gem.
The code used for creating the file is given below:
require 'win32/mmap'
include Win32
mmap = MMap.new(:name => 'myFile', :size => 2000)
mmap.foo = 'hello'
mmap.bar = 27
sleep 100
mmap.close
Now, when we try to read this file in our other application which is in
.Net we get this string {"foo"hello"bari
There were some special symbols also in this string which can't be
posted here so the sample file is attached as an attachment.
So how can we read its contents without the special symbols and without
these foo and bar variables in the other application?
Also is there any way we can write the string directly into the Memory
Mapped file without other variables like here we have used .foo and
.bar?
Attachments:
http://www.ruby-forum.com/attachment/6466/mmap.test
···
--
Posted via http://www.ruby-forum.com/.
I can't speak with authority on win32-mmap as I don't develop for Windows systems. However I can offer some general observations regarding memory-mapped files:
1. ensure you have the file open in binary mode in all programs reading it;
2. keep specific data items at fixed locations in the file;
3. pay attention to concurrency issues - i.e. use file locks defensively;
4. serialise data into an intermediate format that can be decoded in all languages used;
5. use pipes instead - for most real-world use cases they're much less pain to work with.
Ellie
Eleanor McHugh
Games With Brains
http://feyeleanor.tel
···
On 30 Jul 2011, at 11:51, Premjeet Singh H. wrote:
We are creating a Memory Mapped file in ruby using win32-mmap gem.
The code used for creating the file is given below:
require 'win32/mmap'
include Win32
mmap = MMap.new(:name => 'myFile', :size => 2000)
mmap.foo = 'hello'
mmap.bar = 27
sleep 100
mmap.close
Now, when we try to read this file in our other application which is in
.Net we get this string {"foo"hello"bari
There were some special symbols also in this string which can't be
posted here so the sample file is attached as an attachment.
So how can we read its contents without the special symbols and without
these foo and bar variables in the other application?
Also is there any way we can write the string directly into the Memory
Mapped file without other variables like here we have used .foo and
.bar?
----
raise ArgumentError unless @reality.responds_to? :reason