Search code examples
c#managed-c++

Pass 128 bits from managed C++ to C#


I have a function in a managed C++ DLL that needs to pass 128 bits back to C#. I have found quite a bit on the subject calling unmanaged C++ from C# but not so much about managed to managed calls.

This call will happen in a tight loop, potentially billions of times a day across a server farm.

What's the most efficient way to pass back the bits?

So far I considered using a GUID structure as a convenient container for the bits, but it's not clear to me whether or not the .NET runtime will GC that structure, and I'm not sure if that's the most efficient mechanism.


Solution

  • Simply put, passing around variables of the following type defined in C++/CLI:

    public value struct Int128
    {
        System::Int64 lo;
        System::Int64 hi;
    };
    

    should be about the fastest you can do.