• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

15 replies to this topic

### #1Misery  Members

Posted 20 August 2011 - 08:32 AM

Hi,

I wonder if it is possible that two or more applications can have access to the same part of memory.
Lets say I have one program that allocates and fills part of memory with some objects.
And I would like another program to be able to read, modify and write this part of memory.

Is there any name for such technology, some libs, tutorials?

Regards,
Misery

### #2japro  Members

Posted 20 August 2011 - 08:54 AM

Is there any name for such technology,

I think you are searching "Shared memory". The functionality is typically provided by the operation system api.

### #3TheTroll  Members

Posted 20 August 2011 - 09:00 AM

Now do you really want to directly share the memory or do you just want access to the date there? There is a HUGE difference in the two.

### #4rip-off  Moderators

Posted 20 August 2011 - 09:27 AM

Is there any name for such technology

Its called the filesystem.

### #5Antheus  Members

Posted 20 August 2011 - 10:44 AM

I wonder if it is possible that two or more applications can have access to the same part of memory.
Lets say I have one program that allocates and fills part of memory with some objects.
And I would like another program to be able to read, modify and write this part of memory.

Memory is not localized. Entire memory is accessible at any time.

The mere concept of "application" or more accurately, process, is something that is arbitrarily defined by each operating system or runtime system. No such limitation exists when it comes to memory itself.

So a question needs more detail - which OS, which language and what kind of sharing?

### #6AllEightUp  Moderators

Posted 20 August 2011 - 10:49 AM

Hi,

I wonder if it is possible that two or more applications can have access to the same part of memory.
Lets say I have one program that allocates and fills part of memory with some objects.
And I would like another program to be able to read, modify and write this part of memory.

Is there any name for such technology, some libs, tutorials?

Regards,
Misery

As a suggestion, look at the following: http://www.boost.org/doc/libs/1_47_0/doc/html/interprocess.html I'm not a huge fan of boost but for this particular item and a couple others I have no interest in writing such things myself and this is a very reasonable solution so long as you don't have to debug it yourself. I've used this for a shared resource system in cooperative server processes quite successfully and the performance was exceptional and I didn't run into any notable bugs. I think the largest problem I had was proper cleanup given the different Os scoping issues with releasing of the shared memory, all easily dealt with but a pain if you don't think about it up front.

### #7Chargh  Members

Posted 20 August 2011 - 11:05 AM

I wonder if it is possible that two or more applications can have access to the same part of memory.
Lets say I have one program that allocates and fills part of memory with some objects.
And I would like another program to be able to read, modify and write this part of memory.

Memory is not localized. Entire memory is accessible at any time.

The mere concept of "application" or more accurately, process, is something that is arbitrarily defined by each operating system or runtime system. No such limitation exists when it comes to memory itself.

So a question needs more detail - which OS, which language and what kind of sharing?

### #8Antheus  Members

Posted 20 August 2011 - 01:11 PM

This is not entirely true, your application is most likely in its own virtual address space

Which is a concept defined by operating and applies to concept of process.

The the request for details on OS, language, platform, the more the better.

There simply is no generic answer on how to share memory.

### #9Misery  Members

Posted 20 August 2011 - 02:21 PM

In more detail:

lets say first application makes a vector of integers:
int A=new int[100];
for (int i=0;i<100;i++) A[i]=ARandomNumber();


And the second application is supposed to count a sum of the elements of A and fill it with new numbers:
int s=0;
for (int i=0;i<100;i++)
{
s+=A[i];
A[i]=AnotherRandomNumber();
}


This would be supposed to work on Windows 7, but solution for Debian would be cool as well.
The first application could probably put out to an output stream an address to A or something...

### #10rip-off  Moderators

Posted 20 August 2011 - 02:53 PM

Addresses are meaningless between different processes.

A unix solution to this problem would be for the first application to write the array to stdout, and the second application to sum the integers arriving on stdin. You would combine them by using the shell to pipe the output from the first program to the second.

### #11Jacob Jingle  Members

Posted 20 August 2011 - 02:57 PM

Inter-process communication

### #12Slavik81  Members

Posted 20 August 2011 - 04:20 PM

You can use shared memory (which is an OS-dependant solution), but the design you're talking about makes no sense to me. Maybe step back a bit and give us some context. What is the ultimate goal of this system? What is the input? What is the output? What design constraints are there (and why do they exist)?

Addresses are meaningless between different processes.

A unix solution to this problem would be for the first application to write the array to stdout, and the second application to sum the integers arriving on stdin. You would combine them by using the shell to pipe the output from the first program to the second.

He requires 2-way communication, though. I'm not really a command-line guru, so I don't know how you'd do that with pipes.

### #13TheTroll  Members

Posted 20 August 2011 - 04:29 PM

Why don't you just pass the elements you want to add to the app that is holding the data, and then let the app that is responsible for that data pass the number of elements back to the calling app?

The reality is that sharing data between apps is a REALLY REALLY REALLY bad idea. It can lead to more problems then you can could count. You really want one and only one place that can change data.

### #14ApochPiQ  Moderators

Posted 21 August 2011 - 04:21 AM

@The OP: Why do you think you want to do this?
Wielder of the Sacred Wands

### #15rip-off  Moderators

Posted 21 August 2011 - 09:20 AM

Addresses are meaningless between different processes.

A unix solution to this problem would be for the first application to write the array to stdout, and the second application to sum the integers arriving on stdin. You would combine them by using the shell to pipe the output from the first program to the second.

He requires 2-way communication, though. I'm not really a command-line guru, so I don't know how you'd do that with pipes.

I was optimising out the redundant write, since the OP never specified any additional reads afterwards... More seriously, I just failed at reading that post closely enough.

Until we know the high level goal the OP has, it is hard to give concrete advice. I still think that any solution which avoids shared memory should be considered, as the potential for bugs is highest with such an approach.

### #16SimonForsman  Members

Posted 21 August 2011 - 09:43 AM

Addresses are meaningless between different processes.

A unix solution to this problem would be for the first application to write the array to stdout, and the second application to sum the integers arriving on stdin. You would combine them by using the shell to pipe the output from the first program to the second.

He requires 2-way communication, though. I'm not really a command-line guru, so I don't know how you'd do that with pipes.

I was optimising out the redundant write, since the OP never specified any additional reads afterwards... More seriously, I just failed at reading that post closely enough.

Until we know the high level goal the OP has, it is hard to give concrete advice. I still think that any solution which avoids shared memory should be considered, as the potential for bugs is highest with such an approach.

Sockets are a workable solution, and then the two processes don't even have to be on the same machine. (allthough it works best if the communcation can be broken down to messages that can be passed between the processes, for some applications shared memory might very well be the most appropriate solution)
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.