Coder Social home page Coder Social logo

sharedapplication's Introduction

SharedApplication

Full Documentation

Introduction

SharedApplication is a class used for sharing data between processes, and design to be derived by multi-process data structure.

SharedQueue is a lockfree queue with fixed capacity, derived from the SharedApplication. Easy to use.

Usage

SharedApplication

Define a SharedApplication instance in the global namescope

SharedApplication<APPKEY> sApp;

At the begin of the main function, we can do some basic configuration:

sApp.setSize(size_t size);

Set the size of the memory you are going to alloc, and this must called before start. If it wasn't called, then the default size will be 1024 bytes.

void setCPU();
void setCPU(int id);

If you are trying to binding particular CPU (for the better performance), then you may call the setCPU() to automatically bind a CPU;

After the configurations, you can start the sApp, simple write:

sApp.start();

Then, in you program, you can use malloc to alloc memory.

void* ptr = sApp.malloc(size_t size);

But remember, the total size should not excess the capacity decloration before started.

In other program, you can also write the same code. And the contents in the memory allocated is synchronized.

SharedQueue

The SharedQueue is a private inherited form the SharedApplication, means you can just replace SharedApplication with SharedQueue.

shared_application :: SharedQueue<T,capacity,APPKEY> sQueue;

In the main function, you can use...

sQueue::init();//called first
sQueue::push(T &val);
sQueue::pop(T &val);
sQueue::full(T &val);
sQueue::empty(T &val);

Attention

  1. In the SharedApplication, make sure you alloc each memory block using the same order and size

  2. The destructive function must be called, otherwise the shared memory cannot be deleted.

sharedapplication's People

Contributors

mhy12345 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.