Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# shared memory between managed and unmanaged code

Tags:

c#

.net

windows

Is it possible on windows for unmanaged code (c++ / c) to write to an area in memory that is then accessed by managed .Net code (c#) (separate processes) I have a c program that is writing data to an circular memory buffer and I want to process the buffer with unmanaged code.

like image 692
probably at the beach Avatar asked Feb 12 '26 11:02

probably at the beach


1 Answers

If you're looking for a solution where an unmanaged process and managed process can share memory, then you can use the MemoryMappedFile class (introduced in .NET 4.0).

If you're looking to share memory between unmaanged and managed code in the same process, then you can use GCHandle to pin a managed array in memory, and pass it to unmanaged code which can access it.

like image 178
Stephen Cleary Avatar answered Feb 15 '26 01:02

Stephen Cleary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!