Showing results for 
Search instead for 
Did you mean: 

Sharing Data Between Different Instances of the Same CVI DLL or EXE

I need to share data between different instances of the same application or DLL.

Microsoft Visual C++ provides a simple of way of doing this. The Visual C++ compiler lets me name my own data segments. I pass an option to the linker that tells it to share one of these custom data segments, in which case all instances of my module (DLL or EXE) will map to the same instance of my custom data segment. This is accomplished by the following example:
#pragma data_seg(".SHARED")
char pg_pszShared[256] = {0};
#pragma data_seg()
#pragma comment(linker, "/section:.SHARED,RWS")

To explain the Visual C++ example, the "data_seg" pragma tells the compiler to put all the variables following in the specified
data segment. Calling it the second time with no argument tells it to go back to using the default data segment. The "comment" pragma passes an option to the linker that tells it to actually share the specified data section.

Although the solution is easy with Visual C++, I am required to write and build my code with CVI. As far as I can tell, CVI does not support #pragma data_seg. How can I share data between multiple instances of the same DLL in CVI?

Thank you!
0 Kudos
Message 1 of 10
Hi Christine,

See answer to similar question:

The bottom line: CVI does not recognize the #pragma data_seg option.

0 Kudos
Message 2 of 10

I can't get to the link described by Azucena.   I am trying to use TestStand which is called from a CVI application.  I have complex data structures that I don't want to copy all over the place and would like to be able to use pointers.  It appears that the interface from CVi to TestStand uses ActiveX so they don't reside in the same address space.  I was hoping to use shared variables in a DLL to allow this.  Any suggestions would be helpful.



0 Kudos
Message 3 of 10

Why couldn't you use shared named memory?


The Win32 SDK supplied with CVI has plenty of info on how to set up and use shared named memory - it's the only way to share memory between processes in Win32 I believe.  You can use an IPC mechanism to move data between processes, but why bother if you can have each process simply view the same memory?  If one process updates the shared memory, all other sharing processes see the memory updated immediately.


See the topic "file mapping" in the memory management section of MSDN Win32.


It's a bit confusing in that the topic is covered as the sharing of a memory mapped view of some portion of a disk file, but you can use the paging file (AKA "backing file") as the mapped file and it's essentially sharing a portion of each processes' virtual address space with coherence assured since if the OS has to swap out the memory, it gets saved and retrieved from the paging file behind the scenes by the OS - you do no actual file i/o at all.  The net effect is of a shared block of memory between processes.


MSDN also has examples of setting up shared memory in a DLL, so that any process attaching to the DLL gets access to the same shared memory.


We use this all the time.



Message 4 of 10

The Memory Mapped Files worked great.  I never used them before.



0 Kudos
Message 5 of 10

Hi Menchar,


I need to take an analog signal (10 data points at 500 kHz every 200µs) with my PCIe 6341. When I use a standard DAQmx C code and use the DAQmxReadAnalogF64, it is taking 10 ms to bring back the data. I am using a circular buffer and a activated overwrite option in order to lose as less as possible of time, but it s not working.


Do you think that using shared memory can works for me ? How to implement it ?


Thank a lot for your help


ps My code in attachement

0 Kudos
Message 6 of 10
0 Kudos
Message 7 of 10

sorry for the duplication but Menchar looks to have, him, an answer to my question

0 Kudos
Message 8 of 10

David -


I don't think shared memory is going to offer some advantagte per se - shared memory offers a performance advantage over using an IPC (e.g. pipes) to move data between processes, but in this case it would seem to me that the limitation isn't in sharing the data, it's in acquiring it in the first place.


I'm sure someone on the forum or an NI app engineer is all dialed in on how to optimize data rates with the NI board.


Sorry not to be of more help.


Bonne chance,



0 Kudos
Message 9 of 10

Thanks a lot for your answer !


Merci !



0 Kudos
Message 10 of 10