Currently i Writing Code for CallBack Function to Getting Bytes array continuously from CLI Wrapper. My code
C++
**Declaration:**
void ReceivedSensor1ByteArray(unsigned char values[], int length);
**Calling:**
GetSensor1ColorsFromCsharp(&ReceivedSensor1ByteArray);
**Definition:**
byte* sensor1bytevalues;
void ReceivedSensor1ByteArray(unsigned char values[], int length)
{
if(length > 0)
{
sensor1bytevalues=new byte[length];
for(int i = 0; i < length; i++)
{
sensor1bytevalues[i]=values[i];
}
}
}
**CLI Wrapper**
**Decalration:**
public ref class SampleWrapper
{
SampleWrapper(void)
{
kinectSocketwrapperObj->ReadBytesValues+=gcnew CLIWrapperClass::ByteValuesReady(this,&Wrapper::SampleWrapper::ByteArrayReadyMethod);
}
public:
CLIWrapperClass ^ kinectSocketwrapperObj;
static SampleWrapper ^ Instance = gcnew SampleWrapper();
void ByteArrayReadyMethod(array<Byte> ^ values);
**Definition:**
GetByteArrayCallback byteArrayCallback;
__declspec(dllexport) void GetSensor1ColorsFromCsharp(GetByteArrayCallback cb)
{
byteArrayCallback = cb;
CLIWrapperClass ^KinectServerWrapper = SampleWrapper::Instance->kinectSocketwrapperObj;
KinectServerWrapper->ReceiveSensor1colors();
}
void SampleWrapper::ByteArrayReadyMethod(array<Byte> ^ values)
{
Byte *nativeValues = new Byte[values->Length];
copyManagedByteToUnfloatArray(nativeValues, values);
byteArrayCallback(nativeValues, values->Length);
}
void copyManagedByteToUnfloatArray(Byte target[], array<Byte> ^ values)
{
int maxSize = values->Length;
if ( maxSize > 0)
{
for (int index = 0; index < maxSize; index++ )
{
target[index] = (float)values[index];
}
}
}
Actually I Receiving Bytes Data from C# through CLI Wrapper Class and Passed to C++ Application in order to DisplayImageFrame. When i call GetSensor1VerticesFromCSharp function continuesly the system Memory increased after 10 minutes the system gets hanged. please suggest me to solve this issue.