-3

Could someone help me with these questions:

  1. What is the memory (code/data) sections shared by threads within the same process (not shared by different processes)?

  2. Can two processes share their virtual address space?

  3. Can two processes share global variables?

  4. What kind of data sharing can be implemented among processes, using memory mapped files?

  5. Is it possible to share a linked list using memory mapped files? And an array of numbers?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Emy
  • 45
  • 7
  • 2
    One question at a time please. And this looks like homework. Can't you do it yourself? Try and make some effort to research this yourself. – David Heffernan Jun 27 '17 at 15:32

1 Answers1

-1
  1. A process has only one address space. All threads in a single process can access all of the process's memory.

  2. No. On Windows, to share memory across process boundaries, you have to use either a shared data segment, or a memory-mapped file object.

  3. Only if the variables are stored in shared memory.

  4. Any POD data can be shared using a memory mapped file. Consider it a block of raw contiguous bytes. You can share anything that would normally fit in a byte array.

  5. A linked list cannot be shared because its nodes contain pointers to each other in memory, and pointers cannot be used across process boundaries. You would have to serialize the list into a flat format that uses offsets instead of pointers. An array of POD types, like integers, can be shared, yes.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thanks for you response but I still have some doubts for these points: 2. What do you mean by sharing a data segment? From what I understood after searching onthe web, the only way to share data between processes is through file mapping. 5. I think it is possible to have pointers among the shared data but they should be of type _based – Emy Jun 28 '17 at 09:01
  • @Emy See [How do I share data in my DLL with an application or with other DLLs?](https://msdn.microsoft.com/en-us/library/h90dkhs0.aspx), though both approaches are compiler-specific (AFAIK only available in Visual C++), whereas a memory mapped file can be used in any language and compiler with access to the Win32 API. – Remy Lebeau Jun 28 '17 at 14:59