Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use x64 Interlocked Operations against MemoryMappedFiles in .net

I need to use Interlocked Operations (CompareExchange, Increment etc.) against memory in MemoryMappedFiles in .NET.

I found this answer to a very similar question. The problem is that Interlocked Operations are not exported from kernel32 (or any other) dll on 64 bit OS (see e.g. http://blog.kalmbachnet.de/?postid=46).

Is there any other way how I can call Interlocked functions on a block of memory in a 64bit .NET process?

like image 741
Jan Avatar asked Sep 23 '14 10:09

Jan


1 Answers

Write yourself a small C++/CLI helper library that provides interlocked operations consumable by managed code.

I believe the fastest interop path would be to expose a managed class that internally calls into an unmanaged function which itself makes use on the interlocked intrinsics. That way you don't even have to go through PInvoke.

like image 141
usr Avatar answered Sep 28 '22 07:09

usr