Author: r_z_aretr_z_aret
Date: May 10, 2008 11:20
I know this is really a C++, not Win32 question, but I don't hang
around any C++ group, so please tolerate.
If an object is instantiated in the main thread of a program, but
allocates memory when referenced in a worker thread, should that
memory be accessible by the main thread once the worker thread ends?
Example:
I have a class (PFBitMap) that handles BMP and JPEG files. PFBitMap
uses objects in a class (PFString) that handles strings (for filename,
date stamp, etc.). When a PFBitMap object is instantiated, it
instantiates all its PFString objects.
PFString objects allocate memory dynamically (using new).
My program instantiates a few PFBitMap objects. I want to use a worker
thread when one of these objects reads a file. But I ran into problems
when the main thread tried to access the PFString objects (e.g. a date
stamp). No problems if I read files in the main thread or if I make
pre-allocate all the PFStrings.
Pre-allocating the strings seems like a good solution, but I would
like feedback.
|