Hello,
I have unmanaged C++ dll, that I use in a managed code (C++). I call this managed code from C#. It seems to work fine, but I am not sure about the memory management, should I free the data? Here is sample of my code:
#pragma unmanaged
void unmanaged_free (void *p_)
{
free (p_);
}
void *unmanaged_malloc (int size_)
{
return malloc (size_);
}
#pragma managed
void Dnzmq::send (int eid_, void * data_, size_t size_)
{
// Copy data to the unmanaged buffer.
void *data = unmanaged_malloc (size_);
assert (data);
memcpy (data, data_, size_);
// Forward the call to native 0MQ library.
zmq::message_t msg (data, size_, unmanaged_free);
context->api_thread->send (eid_, msg);
}
I call send() function from C#. My question is: who deallocates the function argument data_ ? Is it correct to free *data, that was allocated in unmanaged part of the code?