Jump to content
  • Advertisement
Sign in to follow this  
bikola_p

Global Memory

This topic is 4862 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

Hello, i was wondering if it possible to store something in a specific memory address, so i can refer to it using another language. So for example, in C++, i have int age int main() { cout<<"How old are you"; cin>>age; } and say in VB i want to use age to do say, Print You are (age) years. So basicaly how can i Make Age in this example be used on this level.

Share this post


Link to post
Share on other sites
Advertisement
This might not be the answer your looking for, but you could save the data to a temp file that both programs are aware of. One program opens the file and saves the input in it and closes it, the other file opens it and uses the input for its own purposes... Not so sure that any other way is safe, but i could be wrong.

Share this post


Link to post
Share on other sites
You could use a database but this isn't to point to a memory location. Each application has its own stack and memory. You can't access the memory of another application unless you are making some sort of memory search tool for memory hacking. That is why a database, file or even registry entry would solve this issue for you.

Share this post


Link to post
Share on other sites
I don't know how this would work under Windows, but in Linux/Unix you can use a couple different types of shared memory... namely, the shm_open() and mmap() functions.

However, then you run into all sorts of fun synchronization and mutex problems, just like a multithreaded application, so.

Share this post


Link to post
Share on other sites
It is possible, however the problem lies in trying to tell your VB application the exact location of the memory.

Since you mentioned VB, I'll assume that you're looking for a Windows solution, in which case, you can look into the GlobalAlloc() function, as well as the functions related to it.

Once you have allocated global memory, however, you'll have to use SendMessage() to tell your VB application the resulting HGLOBAL handle.

On top of this, you must also think about thread safety, as well as ensuring that the memory is always valid before doing something with it.

In either case, I would advise you to only use these functions for learning purposes.

Share this post


Link to post
Share on other sites
You can use a file-mapping of the system swap file to create effectively a named shared memory between applications. You must also use proper synchronization methods to prevent any data corruption. Now, how you go about doing that in VB I can't say, though I'm guessing you have to import the relevant Win32 functions involved manually.

Share this post


Link to post
Share on other sites
Problem is the Data is updated every second, and i cant really read and write from a file, its a bit too much.
is it possible though, to specify a memory address to store to, and point to it in VB.

Share this post


Link to post
Share on other sites
That's the magic of the file-mapped swap file. Most of the time, if write caching is enabled, the data is already in physical memory when it is read so no actual file access is necessary.

Share this post


Link to post
Share on other sites
Here's a Microsoft example of how to share memory between processes: Creating Named Shared Memory. It shouldn't be too difficult to convert to VB. It's very likely that similar examples in VB can be found via google.

There are other ways to pass data between applications. The topic is named Interprocess Communications. You can find the details at that link.

@Wavarian, GlobalAlloc allocates memory from the heap. That memory can't be shared between processes without the use of other mechanisms, such as those I just mentioned. Outside of using these mechanisms, there's no guarantee that an address in one process points to anything at all in a second process. Under windows every process has it's own address space.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!