CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 16

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    8

    Unhappy Memory Mapping in Visual C++ programming

    Hi,

    I am doing the memory mapping in between two processes. I used the example from Creating Named and Shared memory from MSDN. I can write and read the data in between two processes, but the problem i am facing is, in middle of this process after some time, some values are read as zero while reading from Process 2 which are written by Process 1, resulting in error in my process. Also tell me whether I have to maintain any timing in between the processes when doing Memory mapping. How to solve this memory reset problem.

    Please help me in solving this problem. Will be waiting for reply.

    Thank You in advance.

  2. #2
    Join Date
    Oct 2011
    Posts
    97

    Re: Memory Mapping in Visual C++ programming

    This may seem obvious, but I have to ask before continuing: are you using a mutex or semaphore to protect access to the memory? Because yes, you do indeed have to maintain timing between the processes. The OS is going to schedule your processes completely randomly (at least to you) and if something needs to happen in a certain order, you need to make sure you do that.

  3. #3
    Join Date
    Jun 2012
    Posts
    8

    Re: Memory Mapping in Visual C++ programming

    Thank You for your reply.

    Actually what i am doing is, i have Process-1 which need hardware details and Process-2 which consists of hardware details. And these details are shared in between these two processes which are available in memory using the memory mapping example from Create Named and Shared memory from MSDN library. I am not using any threads in those two processess and no mutex and no semaphore. So during this I read zero in middle after sometime which results in errors. Please let me know how to proceed further.


    Thank You.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Memory Mapping in Visual C++ programming

    Quote Originally Posted by afroza View Post
    Please let me know how to proceed further.
    We don't have your code. The error can be anything -- maybe your program has a simple bug and has nothing to do with threads or even memory mapped files.

    Until we have your program, compile the code, and duplicate the error, you're the only one right now who should know how to proceed. All I can tell you is to debug your code more thoroughly.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Jun 2012
    Posts
    8

    Re: Memory Mapping in Visual C++ programming

    I have gone through the code, and i am taking log of the data where i am writing continuously 1 and reading continuously 1. In log file writes remain 1 but reading side log changing in middle from 1 to 0 and again 0 to 1.

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Memory Mapping in Visual C++ programming

    Quote Originally Posted by afroza View Post
    I have gone through the code, and i am taking log of the data where i am writing continuously 1 and reading continuously 1. In log file writes remain 1 but reading side log changing in middle from 1 to 0 and again 0 to 1.
    So how does that change the fact that we do not have your code to see what you're doing? You're asking us to magically guess what the issue is, and no one can do that without the code in hand.

    Again, you need to debug further -- you have the program, code, etc. You're in a much better position to see what the problem is then anyone here.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Memory Mapping in Visual C++ programming

    Please edit your post. Add code tags [code]Your code here[/code] and re-indent it to make it readable.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured