From: ranjan sri on
Hi,

I am new to ruby and I want to write code which makes shared memory and
writes to it.Similar to the C code here:

void main(int argc, char* argv[])
{
HANDLE mappedFile = 0;
int oneSecond = 1000;
char* shared = NULL;
HANDLE eventHnd;

eventHnd = CreateEvent(NULL, FALSE, FALSE, "TestSharedEvent");

// STEP 1
mappedFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
PAGE_READWRITE, 0, 4096, "TestSharedMemory");
printf("CreateFileMapping returned %d\n", mappedFile);
fflush(NULL);

// STEP 2
shared = (char*)MapViewOfFile(mappedFile, FILE_MAP_WRITE, 0, 0, 0);
printf("MapViewOfFile returned %p\n", shared);
fflush(NULL);

memset(shared, 0, 4096);
printf("memset worked\n");
fflush(NULL);

int counter = 0;
while (1)
{
sprintf(shared, "value %d", counter++);
printf("Sending new string: %s\n", shared);
SetEvent(eventHnd);
// STEP 5
//Sleep(1000);
}

UnmapViewOfFile(shared);
}

Please suggest .Thanks in advance.
--
Posted via http://www.ruby-forum.com/.

From: Seebs on
On 2010-02-10, ranjan sri <infibit(a)gmail.com> wrote:
> void main(int argc, char* argv[])

Ahem. "int main". (Unless you're in a freestanding environment,
which most people aren't.)

> mappedFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
> PAGE_READWRITE, 0, 4096, "TestSharedMemory");

It might help readers if you mentioned what platform you were
targeting. I've never seen that call, so I can hardly speculate as
to what would replace it, and it seems likely that the corresponding
things might be platform specific.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: di vi on
Seebs wrote:
> On 2010-02-10, ranjan sri <infibit(a)gmail.com> wrote:
>> void main(int argc, char* argv[])
>
> Ahem. "int main". (Unless you're in a freestanding environment,
> which most people aren't.)
>
>> mappedFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
>> PAGE_READWRITE, 0, 4096, "TestSharedMemory");
>
> It might help readers if you mentioned what platform you were
> targeting. I've never seen that call, so I can hardly speculate as
> to what would replace it, and it seems likely that the corresponding
> things might be platform specific.
>
> -s

Well I am on windows Xp.I have been trying to get this working.
http://rubyforge.org/docman/view.php/85/1717/README.html
MMAP on windows.But wasn't successful.Any idea?I did install ruby
http://rubyforge.org/frs/download.php/66872/rubyinstaller-1.9.1-p243-rc1.exe
But do not know the rest of the procedure to get MMAP working.Having
been trying randomly.

Please advice
--
Posted via http://www.ruby-forum.com/.

From: Seebs on
On 2010-02-10, di vi <infibit(a)gmail.com> wrote:
> But do not know the rest of the procedure to get MMAP working.Having
> been trying randomly.

> Please advice

Well, I'm afraid I can't help -- I know nothing about Windows programming.
But with the information about platform in view, perhaps someone else
can help you out!

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!