Shared memory creation in ruby

R

ranjan sri

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.
 
S

Seebs

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
 
D

di vi

Seebs said:
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
 
S

Seebs

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top