Making 2 programs Communicate

Hello, working on a little Neural-net type thing, but I have a small issue, I want my data collecting program, to communicate data with my neural net program.

because they are both programs, I'm not sure if I can use Dll's (since, from my understanding, every time a program links to a DLL it creates a new instance of it)

also, since there is a fair bit of data being transferred, I don't want to make a text file that is constantly being updated, since that will wreck my hard drive pretty fast.

is there a way I can set aside a portion of RAM, use one text file to communicate the pointer to that RAM location, and do it that way? I'm aware that this can be dangerous (if one program closes, freeing that ram area for other programs, and the other app keeps trying to pull/write data from that location it could cause major issues, but I think I can prevent that)


so right now I have one program doing this:

1
2
3
4
5
6
7
8
void OutputData(int &Number)
{
	ofstream myfile;
	myfile.open("C:/Testing/example.txt", ios::binary);
	myfile << &Number;  // Write a pointer location to that int.
	myfile.close();

}



and the other program doing this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <fstream>
#include <string>

using namespace std;


void main()
{
	//read text file to get a memory location.
	string line;
	ifstream myfile("C:/Testing/example.txt", ios::binary);
	if (myfile.is_open())
	{
		while (getline(myfile, line))
		{
			cout << line << '\n';
		}
		myfile.close();
	}

	else cout << "Unable to open file";

	//print out what that memory location says.
	int *a = (int*)line;

	cout << a << " Just checking " << endl;

	cin.get();

}


of course the " int *a = (int*)line; " part doesn't work due to mis-matching data types, but you see my idea (I hope)

but I can't shake the feeling there must be a better way.
Last edited on
https://www.geeksforgeeks.org/ipc-shared-memory/

also boost, if you use it (you should at least know generally what it is and does) has great tools for this as well.
That looks perfect! lets hope I can get it to work =D

Thank you!
Just an update for any future people with the same issue:

Linux/Unix/etc Users: https://www.geeksforgeeks.org/ipc-shared-memory/
^ that should work fine, (don't know for sure though, since I'm not a Linux user)

Windows Users: https://docs.microsoft.com/en-us/windows/win32/memory/creating-named-shared-memory
^ That should work, HOWEVER, it requires administrative privileges, easiest fix: after compiling (and getting 'error 5 or 2' depending) track down the bianary(.exe) file on the hard-drive (usually in ...programName/Debug) Right click the file, and 'Run as Administrator'

should work for you then. (worked great for me)
Topic archived. No new replies allowed.