jiing wrote:
Now I am try to transfer a memory pointer between two threads.
but there has a error mesage.
_CrtIsValidHeapPointer(pUserData) in dbgheap.c
I lookup google and find it's seems to be the local heap in the two
threads are different. so their memory that pointer point to are
different.
I want to ask
how to pass a complete memory block between two threads enclosed in a
COM
Memory is not owned by threads, but by processes. All threads of a process
have equal access to any block of memory allocated by that process.
Most likely you're running into a problem where you're allocating memory by
one method (e.g. malloc) and deleting it by another (e.g. delete).
The COM solution to passing memory ownership between threads is to alloc
memory using CoTaskMemAlloc and free it using CoTaskMemFree. Depending on
the signatures of the COM function you're calling, there are circumstances
when the COM runtime will _require_ that a block of memory was allocated
this way, because the runtime will de-allocate it for you (for example, an
[in,out] parameter).
-cd