Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:18:05+00:00 2026-06-13T01:18:05+00:00

I have shared memory communication successful between two processes on Windows. I write to

  • 0

I have shared memory communication successful between two processes on Windows. I write to it like this:
enter image description here

Don’t mind my comments to myself. I thought I’d have some fun with the diagram.
How can I do this faster? In-other words, how can I do this using a Mutex or CreateEvent? I tried hard to understand Mutexes and CreateEvent but it confuses me on MSDN as it uses on application and a thread. An example would be helpful but isn’t required.

The way I do current do it is (Very SLOW!):

//Create SharedMemory Using Filename + KnownProcessID so I can have multiple clients and servers with unique mappings. I already have this working and communication successful.

bool SharedMemoryBusy()
{
    double* Data = static_cast<double*>(pData);   //Pointer to the mapped memory.
    return static_cast<int>(Data[1]) > 0 ? true : false;
}

void* RequestSharedMemory()
{
    for (int Success = 0; Success < 50; ++Success)
    {
        if (SharedMemoryBusy())
            Sleep(10);
        else
            break;
    }
    return pData;
}

bool SharedMemoryReturned()
{
    double* Data = static_cast<double*>(pData);
    return static_cast<int>(Data[1]) == 2 ? true : false;
}

bool SharedDataFetched()
{
    for (int Success = 0; Success < 50; ++Success)
    {
        if (SharedMemoryReturned())
            return true;

        if (!SharedMemoryBusy())
            return false;

        Sleep(10);
    }
    return false;
}

The reading and writing part (Just an example of on request.. There can be many different types.. Models, Points, Locations, etc):

void* GLHGetModels()
{
    double* Data = static_cast<double*>(RequestSharedMemory());
    Data[0] = MODELS;
    Data[1] = StatusSent;

    if (SharedDataFetched())
    {
        if (static_cast<int>(Data[2]) != 0)
        {
            unsigned char* SerializedData  = reinterpret_cast<unsigned char*>(&Data[3]);
            MemDeSerialize(ListOfModels, SerializedData, static_cast<int>(Data[2]));
            return Models.data();
        }
        return NULL;
    }
    return NULL;
}

void WriteModels()
{
    If (pData[0] == MODELS)
    {
        //Write The Request..
        Data[1] = StatusReturned;
        Data[2] = ListOfModels.size();
        unsigned char* Destination = reinterpret_cast<unsigned char*>(&Data[3]);
        MemSerialize(Destination, ListOfModels); //Uses MEMCOPY To copy to Destination.
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:18:06+00:00Added an answer on June 13, 2026 at 1:18 am

    You can use events and mutexes between processes. This works fine. You only need to duplicate the handle of the object before passing it to other process:

    BOOL WINAPI DuplicateHandle(
      _In_   HANDLE hSourceProcessHandle,
      _In_   HANDLE hSourceHandle,
      _In_   HANDLE hTargetProcessHandle,
      _Out_  LPHANDLE lpTargetHandle,
      _In_   DWORD dwDesiredAccess,
      _In_   BOOL bInheritHandle,
      _In_   DWORD dwOptions
    );
    

    Each process works with its own handle while they both refer to the same kernel object.

    What you need to do is to create 2 events. First party will signal that the data is ready. Other side shoud take the data, place its own data, reset first event and signal the second. After that the first party is doing the same.

    Event functions are: CreateEvent, SetEvent, … CloseHandle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Two Windows processes have memory mapped the same shared file. If the file consists
I have two process and a shared memory zone, my workflow is like this.
I understand that in CUDA's memory hierachy, we have things like shared memory, texture
Can I use shared memory on Windows in order to have a common memory
Does Windows have the notion of system-wide shared memory segments and is there a
I would like to have a manager process sharing graphs via shared memory, read-only
This is about memory-based IPC (like to LocalService example) but for two apps running
I have hard time managing children processes via signals and shared-memory (I know pipes
I have two programs interacting via a shared memory segment. When using the segment
I have a chunk of shared memory containing some data. Reading / writing this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.