I’ve got a fairly specific problem i’ve been struggling with for a couple of days.
I’m using a native C++, one of the methods takes a ptr to a struct containing fixed size char arrays.
e.g.
struct userData {
char data1[10];
char data2[10];
};
method:
short AddItem(long id, userData* data);
I’m trying to call to call this from Managed VC++ but I need to have an instance of userData I can keep hold of in my managed class.
Can anyone help with how to achieve this?
Thanks
I use one of the following two containers when friendly interop with garbage collection is preferred:
The previous container looks sufficient for your needs. You can use it as follows:
The advantage of the previous approach is that even if you forget to dispose of the objects, the memory pressure is reasonably updated so that garbage collection occurs at the appropriate frequency.
If you know the size of the data element you’re allocating roughtly, but it’s not merely the direct size (i.e. the native struct or class allocates memory internally), the following variant may be more appropriate: