Jump to content
  • Advertisement
Sign in to follow this  
Misery

Access to one program from another

This topic is 2526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

Is there any name for such technology,

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

[quote name='Misery' timestamp='1313850744' post='4851603']
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?
[/quote]

This is not entirely true, your application is most likely in its own virtual address space (that is why two applications with the same entry point address can run simultaneously). So the OS is able to address physical memory in a linear way however your application is bound to his virtual address space and an other applications virtual address space would have to mapped to your virtual address space resulting in a different address for the same data (say app1 has code at 0xDEADBEEF and wants to access address 0xDEADBEEF of app2 it will have to be mapped at an other address then the original address). This is not really a problem unless the data you are trying to access contains pointers to addresses within this mapped memory (or even worse inside app2's private memory, then there is no way to know what will happen the address could be perfectly legal and pointing to valid data in app1 resulting in unpredictable results).

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites
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=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;
A=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...
:D

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!