SharedMemory | shared memory classes for sharing data

 by   spazzarama C# Version: v2.3.2 License: Non-SPDX

kandi X-RAY | SharedMemory Summary

kandi X-RAY | SharedMemory Summary

SharedMemory is a C# library. SharedMemory has no bugs, it has no vulnerabilities and it has low support. However SharedMemory has a Non-SPDX License. You can download it from GitHub.

The SharedMemory class library provides a set of C# classes that utilise memory mapped files for fast low-level inter-process communication (IPC). Originally only for sharing data between processes, but now also with a simple RPC implementation. The library uses the .NET MemoryMappedFile class in .NET 4.0+, and implements its own wrapper class for .NET 3.5.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              SharedMemory has a low active ecosystem.
              It has 409 star(s) with 98 fork(s). There are 36 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 14 open issues and 25 have been closed. On average issues are closed in 81 days. There are 1 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of SharedMemory is v2.3.2

            kandi-Quality Quality

              SharedMemory has 0 bugs and 0 code smells.

            kandi-Security Security

              SharedMemory has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              SharedMemory code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              SharedMemory has a Non-SPDX License.
              Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.

            kandi-Reuse Reuse

              SharedMemory releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of SharedMemory
            Get all kandi verified functions for this library.

            SharedMemory Key Features

            No Key Features are available at this moment for SharedMemory.

            SharedMemory Examples and Code Snippets

            No Code Snippets are available at this moment for SharedMemory.

            Community Discussions

            QUESTION

            Shared-memory IPC solution for both Linux and Windows
            Asked 2022-Mar-28 at 01:00

            Below is a simple and perfect solution on Windows for IPC with shared memory, without having to use networking / sockets (that have annoying limits on Windows). The only problem is that it's not portable on Linux:

            Avoiding the use of the tag parameter will assist in keeping your code portable between Unix and Windows.

            Question: is there a simple way built-in in Python, without having a conditional branch "if platform is Windows, if platform is Linux" to have a shared-memory mmap?

            Something like

            ...

            ANSWER

            Answered 2022-Mar-23 at 08:23

            The easiest way is to use python with version >=3.8, it has added a built-in abstraction for shared memory, it works on both windows and linux https://docs.python.org/3.10/library/multiprocessing.shared_memory.html

            The code will look something like this:

            Process #1:

            Source https://stackoverflow.com/questions/71479189

            QUESTION

            shmget returns different id for same key
            Asked 2022-Mar-03 at 13:42

            Hello I made small 'client-server' file transfer program in Linux. But something strange is happening. If I launch first client and then server everything work fine. shmget() giving same id for provided key. Unfortunately if I launch first server and then client I am getting different id in client and I cannot copy data. I am using IPC_CREAT flag so it should join to shared memory.

            client

            ...

            ANSWER

            Answered 2022-Mar-03 at 13:42

            Fixed: I cannot mark semaphore to detach until client will join to it

            Source https://stackoverflow.com/questions/70183218

            QUESTION

            Is there a way to convert array of bytes to array of floats
            Asked 2022-Jan-25 at 12:30

            I did a python script that gets data from shared mem and convert it from bytes to floats. The main problem is that it very slow.

            This is how I init the shared memory:

            ...

            ANSWER

            Answered 2022-Jan-25 at 12:30

            You can use np.frombuffer to construct a Numpy array from a bytes object:

            Source https://stackoverflow.com/questions/70848501

            QUESTION

            Python Multiprocessing Pipe is very slow (>100ms)
            Asked 2022-Jan-20 at 13:14

            I'm currently writing an image processing program in Python 3.x that needs to process frames in real-time (30 FPS) with low-latency (<60ms). I have 1 parent process that reads frames and sends them to multiple child processes via a SharedMemory object. The computations done by the child processes are CPU bound and running all of them on a single core is not possible at 30 FPS. But since they work independently of each other, I decided to run them as separate processes.

            Currently, I'm using Pipes to send commands to the child processes, most importantly to inform them whenever the frame is updated. On measuring the time between the send() command of the parent and the recv() command on the child, the latency is always >100ms. I used time.time_ns() for this.

            This is a problem because the output feed will now always be lagging by >100ms + time taken by all the children to finish processing (another 20-30ms + the delays between all the send() functions).

            The application is meant to be used on a live sports feed and therefore cannot introduce such a high latency. So I have exactly 2 questions:

            1. Are Pipes actually that slow in Python? Or is something wrong with my implementation of them. (Note: I have tested the latency on an Intel i5 9th Gen as well as an Apple M1)

            2. If Pipes indeed are this slow, do I have any other options in Python? Other than resorting to some form of sockets?

            Thanks.

            Edit:

            I've added the code I've used to test the Pipe latency here.

            ...

            ANSWER

            Answered 2022-Jan-20 at 13:14

            Just wrote one possible solution for you, using multiprocessing objects Process and Queue.

            I measured its throughtput speed and it takes on average 150 mcs (micro-seconds) to process one task that does almost nothing. Processing just takes integer number from a task, adds 1 to it and sends it back. I think 150 micro-seconds delay should be totally enough for you to process 30 FPS.

            Queue is used instead of your Pipe, as I think it is more suitable for multi-task processing. And also if your time measurements are precise then Queue is also 660x times faster than Pipe (150 Micro seconds compared to 100 Milli seconds delay).

            You can notice that processing loop sends tasks in batches, meaning that first it sends many tasks to all processes and only after that gathers all sent and processed tasks. This kind of batch processing makes processing smooth, compared to sending just 1 task at a time and then gathering few results.

            Even better would be if you send tasks to processes and then gather results asynchrounously in separate lighweight threads. This will prevent you blocking on waiting slowest process to finish tasks.

            Processes are signalled to finish and exit by sending None task to them.

            Try it online!

            Source https://stackoverflow.com/questions/70784547

            QUESTION

            segmentation fault (exit code 139 (interrupted by signal 11: SIGSEGV)) when using multiprocessing.shared_memory.ShareMemory in Python
            Asked 2021-Dec-06 at 19:56

            I'm trying to load List[np.ndarray] into shared_memory such that other processes can directly access this shared_memory and recover the original List[np.ndarray] without copying List[np.ndarray] into every process. The detailed motivation is related to my previous question: share read-only generic complex python object with int, list of numpy array, tuple, etc. as instance field between multiprocessing

            I wrote the following code(python version: 3.8.12, Numpy:1.20.3, MacOS):

            encode_nd_arr_list(): given List[np.ndarray], I can get List of share_memory name. decode_nd_arr_list(): given List of share_memory name, I can recover original List[np.ndarray].

            ...

            ANSWER

            Answered 2021-Dec-06 at 09:27

            The buffers that are used in each iteration of the loop in the decode_nd_arr_list method get closed after the corresponding SharedMemory object goes out of scope and that causes the segfault. You are essentially trying to access a memory that is no longer valid.

            In order to fix it, you can create a custom object that wraps around the ndarray and also stores the SharedMemory to prevent it from going out of scope.

            Example:

            Source https://stackoverflow.com/questions/70242508

            QUESTION

            Why does python's SharedMemory seem to initialize arrays to zeros
            Asked 2021-Nov-17 at 17:35

            I'm initializing a SharedMemory in python to be shared between multiple processes and I've noticed that it always seems to be filled with zeros (which is fine), but I don't understand why this is occurring as the documentation doesn't state there is a default value to fill the memory with.

            This is my test code, opened in two seperate power shells, shell 1:

            ...

            ANSWER

            Answered 2021-Nov-17 at 17:35

            This is operating system dependent. Python doesn't initialize the memory - it just takes the virtual memory address offered by the operating system. On posix systems it uses shm_open, while on Windows its CreateFileMapping. On linux and windows, these calls guarantee that memory is initialized to zero.

            It would be a security leak to let the application see whatever left over data happens to be in the RAM from the previous user, so it needs to be filled with something. But this isn't a guarantee from python and its possible that some operating systems (embedded OS perhaps) don't do things that way.

            Source https://stackoverflow.com/questions/69992434

            QUESTION

            How SharedMemory in python define the size?
            Asked 2021-Nov-03 at 11:01

            I have some prolem about SharedMemory in python3.8,any help will be good.

            Question 1.

            SharedMemory has one parameter SIZE,the doc tell me the unit is byte.I created a instance of 1 byte size,then, let shm.buf=bytearray[1,2,3,4], it can work and no any exception!why?

            Question 2.

            why print buffer is a memory address?

            why i set size is 1byte,but result show it allocate 4096byte?

            why buffer address and buffer[3:4] address is 3X16X16byte far away?

            why buffer[3:4] address same as buffer[1:3] address?

            ...

            ANSWER

            Answered 2021-Nov-03 at 11:01

            In answer to question 2:

            buffer[3:4] is not, as you seem to suppose, an array reference. It is an expression that takes a slice of buffer and assigns it to a new unnamed variable, which your function prints the ID of, then throws away. Then buffer[1:3] does something similar and the new unnamed variable coincidentally gets allocated to the same memory location as the now disappeared copy of buffer[3:4], because Python's garbage collection knew that location was free.

            If you don't throw away the slices after creating them, they will be allocated to different locations. Try this:

            Source https://stackoverflow.com/questions/69820911

            QUESTION

            Fast communication between C++ and python using shared memory
            Asked 2021-Nov-02 at 07:11

            In a cross platform (Linux and windows) real-time application, I need the fastest way to share data between a C++ process and a python application that I both manage. I currently use sockets but it's too slow when using high-bandwith data (4K images at 30 fps).

            I would ultimately want to use the multiprocessing shared memory but my first tries suggest it does not work. I create the shared memory in C++ using Boost.Interprocess and try to read it in python like this:

            ...

            ANSWER

            Answered 2021-Sep-15 at 19:53

            So I spent the last days implementing shared memory using mmap, and the results are quite good in my opinion. Here are the benchmarks results comparing my two implementations: pure TCP and mix of TCP and shared memory.

            Protocol:

            Benchmark consists of moving data from C++ to Python world (using python's numpy.nparray), then data sent back to C++ process. No further processing is involved, only serialization, deserialization and inter-process communication (IPC).

            Case A:

            Communication is done with TCP {header + data}.

            Case B:

            • One C++ process implementing TCP communication using Boost.Asio and shared memory (mmap) using Boost.Interprocess
            • One Python3 process using standard TCP sockets and mmap

            Communication is hybrid : synchronization is done through sockets (only header is passed) and data is moved through shared memory. I think this design is great because I have suffered in the past from problem of synchronization using condition variable in shared memory, and TCP is easy to use in both C++ and Python environments.

            Results: Small data at high frequency

            200 MBytes/s total: 10 MByte sample at 20 samples per second

            Case Global CPU consumption C++ part python part A 17.5 % 10% 7.5% B 6% 1% 5% Big data at low frequency

            200 MBytes/s total: 0.2 MByte sample at 1000 samples per second

            Case Global CPU consumption C++ part python part A 13.5 % 6.7% 6.8% B 11% 5.5% 5.5% Max bandwidth
            • A : 250 MBytes / second
            • B : 600 MBytes / second
            Conclusion:

            In my application, using mmap has a huge impact on big data at average frequency (almost 300 % performance gain). When using very high frequencies and small data, the benefit of shared memory is still there but not that impressive (only 20% improvement). Maximum throughput is more than 2 times bigger.

            Using mmap is a good upgrade for me. I just wanted to share my results here.

            Source https://stackoverflow.com/questions/69091769

            QUESTION

            Sharing two strings of data between processes in C++
            Asked 2021-Oct-27 at 17:29

            I've come into a problem recently where I had two separate processes that need to share two strings. (A dynamic IP address and a key) I'm used to using ROS for this, where I would define a ROS msg with the two strings and send it from one to the other.

            However we are trying to go as simple as possible with our application here and thus avoid using third party SW as much as we can. To do so I originally planned to use shared memory to send a struct holding both std::string only to realize it is not a trivial problem as this struct's size is dynamic...

            I've also thought of using other means like sockets or queues, but I always run into the problem of not knowing beforehand the size of this struct. How can one deal with this problem? Is there a way to do so that doesn't involve defining some protocol where you prepend the string with its size and end it with a null, or similar?

            Here is a snip of my code that uses Qt to create a SharedMemory to pass this struct (unsuccessfully of course).

            ...

            ANSWER

            Answered 2021-Oct-27 at 13:57

            Shared memory should be fine (you even let Qt do all the hard work) What you need is probably something like this, something that has a fixed size in your shared memory and still has enough space to hold your strings.

            Source https://stackoverflow.com/questions/69739846

            QUESTION

            Python create SharedMemory instance using existing buffer (bytes from marshal.dumps())
            Asked 2021-Oct-24 at 21:03

            I would like to create an instance of multiprocessing.shared_memory.SharedMemory passing from outside the buffer to use to hold the data.

            My use case is the following:

            ...

            ANSWER

            Answered 2021-Oct-24 at 21:03

            Passing a buffer object to a SharedMemory instance seems to be impossible at the moment (Python 3.9). The best I have achieved is to use slice assignment to copy the data (which is way faster than using a for loop, if you are using CPython).

            Source https://stackoverflow.com/questions/69530701

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install SharedMemory

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries

            Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link