atlaste
atlaste

Reputation: 31116

Temporarily pinning everything

I'm attempting to marshal a forest of objects from C# .NET to native C++. That is: I have a graph of hundreds of millions of objects (if not more), that I wish to use in native C++. See it as a normal 'leaf'/'node' construction with pointers between leafs and nodes. I control both the C++ and the C# code, so I can make adjustments to the code.

The inner loop of the software is going to be implemented in native C++ for performance reasons. I basically want to tell the GC to stop for a while (to ensure objects aren't moved), then do the fancy C++ routine, and then continue the GC once it's done.

There are also things that I don't want to do:

So, any suggestions on how to do this?

Upvotes: 0

Views: 73

Answers (1)

Ian Ringrose
Ian Ringrose

Reputation: 51927

I will look at using managed C++.

  • Maybe accessing the .NET objects from manage C++ will be fast enough.
  • Otherwise use managed C++ to “walk” the .net objects and create native C++ objects, delete them all once done.
  • Or create a class factory class in manage C++ that can be used to create the C++ object being callable from C#, once again delete them all once done.
  • Or do as Marc Gravel says and manually allocating a buffer of unmanaged memory, and dealing with structs inside that space, maybe using a code generator driven from attributes on your C# classes.

Upvotes: 1

Related Questions