send params to unmanaged functions

R

roni

hi.
i have gc class that wraps call to unamanged function.
im confuse with the paramter allocation and gc when sending.
i wrote small sample ,to understand if i this is ok.

__gc class MyManagedClass{
public:

void Func1(){

UNAMANGEDDLL_DATA_ST dataSt ; //not pointer
m_pArr=new UNAMANGEDDLL_DATA_ST[15]; // point to array of structs
m_pDataSt = new UNAMANGEDDLL_DATA_ST; // point to struct


unamangedFunction(dataSt,m_pArr,m_pDataSt,m_nNumber ); // is there
problem to send this parameter to unmanaged function ? memory
problems ?
}

private:
UNAMANGEDDLL_DATA_ST * m_pDataSt ;
int m_nNumber ;
UNAMANGEDDLL_DATA_ST * m_pArr;

}

=================================================================
my question is:

all of the 4 parameters are __nogc ?
the gc deal with this paramters ? move them ? free them ?
is there somthing i need to do before sending this parameters to the
unmanaged function , or its safe ?
==================================================================
 
A

Alon

roni said:
hi.
i have gc class that wraps call to unamanged function.
im confuse with the paramter allocation and gc when sending.
i wrote small sample ,to understand if i this is ok.

__gc class MyManagedClass{
public:

void Func1(){

UNAMANGEDDLL_DATA_ST dataSt ; //not pointer
m_pArr=new UNAMANGEDDLL_DATA_ST[15]; // point to array of structs
m_pDataSt = new UNAMANGEDDLL_DATA_ST; // point to struct


unamangedFunction(dataSt,m_pArr,m_pDataSt,m_nNumber ); // is there
problem to send this parameter to unmanaged function ? memory
problems ?
}

private:
UNAMANGEDDLL_DATA_ST * m_pDataSt ;
int m_nNumber ;
UNAMANGEDDLL_DATA_ST * m_pArr;

}

=================================================================
my question is:

all of the 4 parameters are __nogc ?
the gc deal with this paramters ? move them ? free them ?
is there somthing i need to do before sending this parameters to the
unmanaged function , or its safe ?
==================================================================

Hi Ronny.
Every thing is O.K.
You are passing two parameters by value ( dataSt and m_nNumber ), so
you don't need to care about them. You are passing two parameters as
pointers (m_pArr,m_pDataSt), they will not move in memory (they are
native type, and the new is like the old C++ new), but you do have to
delete them in unamangedFunction, as you should always do in native
code.

Alon Fliess
CTO
The Sela Group
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top