Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jiing - 02 May 2005 04:03 GMT
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 - 02 May 2005 10:06 GMT
I use vector can transfer memory block between threads.
Thanks
Carl Daniel [VC++ MVP] - 02 May 2005 14:17 GMT
> 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
Carl Daniel [VC++ MVP] - 02 May 2005 14:16 GMT
> Now I am try to transfer a memory pointer between two threads.
> but there has a error mesage.
[quoted text clipped - 9 lines]
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.