Giter Site home page Giter Site logo

sharedmemory's Introduction

SharedMemory

Q&A

Q: What does the header do?
A: This is a template for shared memory.

Q: How many platforms it support?
A: It only support Windows now.
A: I have implemented linux version! I put it in linux branch!

Q: Does it has mutex in reading or writing?
A: No, you can implement mutex by yourself.
A: I have implemented mutex version! Try MutexSharedMemory!

Q: How to create a SharedMemory with specific length, like 10 bytes?
A: Define a struct contian 10 bytes or use char[10] as T.

Example one
    struct TenBytes{
        char[10] data;
    }
    SharedMemory<TenBytes> sm("SharedMemory", CREATE_RW);
Example two
    SharedMemory<char[10]> sm("SharedMemory", CREATE_RW);

Q: How to create a SharedMemory with initial value?
A: Use constructer to pass initial value!

How to use it?

#include <iostream>
#include "SharedMemory.h"

using namespace std;
using namespace SharedMemoryTemplate;

int main()
{
	try{
		auto sm = new SharedMemory<int>("SharedMemory", CREATE_RW);
		int a = 100;
		while (true)
		{
			sm->write(&a);
			cout << a << endl;
			a++;
		}
	}
	catch (ErrorCode error)
	{
		cout << error << endl;
	}
	system("pause");
	return 0;
}
#include <iostream>
#include "SharedMemory.h"

using namespace std;
using namespace SharedMemoryTemplate;

int main()
{
	try
	{
		auto sm = new SharedMemory<int>("SharedMemory", OPEN_RW);
		int a = 100;
		while (true)
		{
			sm->read(&a);
			cout << a << endl;
		}
	}
	catch (ErrorCode error)
	{
		cout << error << endl;
	}
	system("pause");
	return 0;
}

sharedmemory's People

Contributors

cwlmyjm avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.