How to transfer a memory block(not pointer) between two threads

  • Thread starter Thread starter jiing
  • Start date Start date
J

jiing

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

thanks in advance.

-jiing-
 
jiing said:
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
 
jiing said:
I use vector can transfer memory block between threads.

There's little about std::vector that makes it more or less appropriate for
passing between threads than any other method. The one thing that it will
get you is matched allocation and deallocation (which is no doubt what your
problem was in the first place).

-cd
 
Back
Top