shared-memory

stream data from c++ to c# over shared memory

半城伤御伤魂 提交于 2019-12-03 17:03:06
问题 I am attempting to stream data from a c++ application to a C# application using shared memory. Based on example I found, I have: c++ (sending) struct Pair { int length; float data[3]; }; #include <windows.h> #include <stdio.h> struct Pair* p; HANDLE handle; float dataSend[3]{ 22,33,44 }; bool startShare() { try { handle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(Pair), L"DataSend"); p = (struct Pair*) MapViewOfFile(handle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0,

How Do I Store and Retrieve a Struct into a Shared Memory Area in C

旧街凉风 提交于 2019-12-03 14:29:46
For a uni assignment I need to create a circular list of up to 10 file names, and then store these in a shared memory area, so that 2 child processes can read/write to the list (using a semaphore to control access). Trouble is, that I am a total C novice and I feel loss and despair because its totally out of my depth. I need some help in "filling in the holes" of my knowledge. Right now, I am simply focussing on it one problem at a time, and presently, I am only trying to get my circular list into the shared memory area. So far I have: typedef struct FILE { struct FILE *f_link; /* forward link

accessing shared variable from inside a Runnable class

强颜欢笑 提交于 2019-12-03 14:17:29
I need to define a shared variable in my Main class's main() method. I need two threads to be able to access that shared variable. Im creating the threads by implementing the Runnable interface and implementing the abstract run() method of the interface. How do i refer to the shared variable defined in the Main class's main() method from within the run() method defined in my class that implements the Runnable interface? Obviously just calling them by name is not working - as they appear out of my Runnable class's scope. EDIT - apologies, here is a simple example public Class DoThread

Windows: Resize shared memory

前提是你 提交于 2019-12-03 13:55:33
When I create a shared memory segment on Windows (like CreateFileMapping(INVALID_HANDLE_VALUE, ...) ), is there any way to resize it, other than creating a bigger segment and copying the data? I've read in MSDN that file mappings have a fixed size, but is there possibly some way to make a new mapping over the same memory? Like in Linux, where you can use shm_open() and then ftruncate() and mmap() it again. The short answer is no - you cannot resize a file mapping once it has been created. The create/copy sequence you describe is the only way I'm aware of to accomplish this with file mappings

Do I need to use shm_unlink on a shared memory object?

痞子三分冷 提交于 2019-12-03 13:48:01
I've written a server (GNU C++ / Linux) which runs continuously, and occasionally executes small stand-alone programs to do work. In order to efficiently get data to the worker programs, the server creates and maps a shared memory object (code abbreviated for clarity): int fd = shm_open("/shm_file", O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR); ftruncate(...); data = mmap(...); // etc... launchWorker(...); // Start the worker program The worker program then opens this shared memory in a similar way (except read-only, without the O_CREAT and O_TRUNC, i.e. we assume it already exists). When

Is it possible to store polymorphic class in shared memory?

牧云@^-^@ 提交于 2019-12-03 13:41:05
问题 Suppose I have class Base and Derived : public Base . I have constructed a shared memory segment using boost::interprocess library. Is it possible to have code similar to this: Base* b = new Derived(); write(b); //one app writes Base* b2 = read(b); //second app reads //b equals b2 (bitwise, not the ptr location) The problems I see here is for instance that the required space for a derived class of Base is unknown (so how much shmem to allocate?) Q : how to pass objects via pointers between

Why are multiprocessing.sharedctypes assignments so slow?

梦想与她 提交于 2019-12-03 13:28:53
Here's a little bench-marking code to illustrate my question: import numpy as np import multiprocessing as mp # allocate memory %time temp = mp.RawArray(np.ctypeslib.ctypes.c_uint16, int(1e8)) Wall time: 46.8 ms # assign memory, very slow %time temp[:] = np.arange(1e8, dtype = np.uint16) Wall time: 10.3 s # equivalent numpy assignment, 100X faster %time a = np.arange(1e8, dtype = np.uint16) Wall time: 111 ms Basically I want a numpy array to be shared between multiple processes because it's big and read-only. This method works great, no extra copies are made and the actual computation time on

Placing Python objects in shared memory

﹥>﹥吖頭↗ 提交于 2019-12-03 12:45:24
问题 Is there a Python module that would enable me to place instances of non-trivial user classes into shared memory? By that I mean allocating directly in shared memory as opposed to pickling into and out of it. multiprocessing.Value and multiprocessing.Array wouldn't work for my use case as they only seem to support primitive types and arrays thereof. The only thing I've found so far is POSH, but it hasn't changed in eight years. This suggests that it's either super-stable or is out of date.

Sharing heap memory with fork()

╄→尐↘猪︶ㄣ 提交于 2019-12-03 12:43:56
I am working on implementing a database server in C that will handle requests from multiple clients. In order to do so I am using fork() to handle connections for individual clients. The server stores data in the heap which consists of a root pointer to hash tables of dynamically allocated records. The records are structs that have pointers to various data-types. I would like for the processes to be able to share this data so that when a client makes a change to the heap the changes will be visible for the other clients. I have learned that fork() uses COW (Copy On Write) and my understanding

**Non-Boost** STL allocator for shared memory

南笙酒味 提交于 2019-12-03 11:28:41
Due to policy where I work, I am unable to use a version of Boost newer than 1.33.1 and unable to use a version of GCC newer than 4.1.2. Yes, it's garbage, but there is nothing I can do about it. Boost 1.33.1 does not contain the interprocess library. That said, one of my projects requires placing an std::map (or more likely an std::unordered_map ) in to shared memory. It is only written/modified ONE TIME when the process loads by a single process (the "server") and read by numerous other processes. I haven't done shared memory IPC before so this is fairly new territory for me. I took a look