|
It's not the class that will have it's own heap it's the DLL. If you statically link a DLL to the CRT, e.g. LIBCMTD.LIB then the heap code get compiled into the DLL and it therefore gets it's own heap whenever it is loaded. If it's later used with an EXE that links to the CRT either statically or dynamically then they have 2 separate heaps.
If everything links dynamically then every module uses the one MSVCRT.DLL loaded into the process and they all share the one heap. It sounds like a plausible cause for your error if ThreadPool is in its own DLL. I'll try a little ASCII art as I'm not that good at explaining it.
--MY.exe Process space in memory--
[
{
//Main function is here
//new or delete here uses late bound MSVCRT.Dll
}
--Kernel32.Dll--
--OtherWindows.Dll--
--ThreadPool.Dll--
[
{
//ThreadPool code is here
//new or delete here is fixed at compile time to call LIBCMTD code linked in below
}
LIBCMTD.LIB link inserts CRT code here
{
//ThreadPool.Dll is early bound to this code so it uses this heap
//Heap code is here
}
]
--MoreWindows.Dll--
--MSVCRT.Dll--
{
//This dynamically linked code is used by MY.exe which binds to it after it's loaded
//Heap code is here
}
]
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Well, I don't exactly want to combine the two together, since ThreadPool should be its own component (and used by other classes as well). This is what I tried and it does fix the problem (as well as the source of the problem).
Given that I call pThreadPool->Release(), it would only make sense to somehow acquire the ThreadPool object from the ThreadPool class itself, so I just created the following static function from within the ThreadPool:
ThreadPool* ThreadPool::Create()
{
ThreadPool* pThreadPool = new ThreadPool();
return pThreadPool;
}
Thanks a lot for your help, Matt. I always used to think the "heap" was one global section of memory that the entire process handled, and that any new or delete would dump things onto that heap. It seems like the concept is not so simple and there can be multiple heaps...
|
|
|
|
|
I give the following advice about once a month (recently every few days); it often helps me track down the nastier heap errors:
Try enabling the page heap[^] for your process. Follow these steps:
1. Download and install WinDBG[^].
2. Select “Start”->“All Programs”->“Debugging Tools for Windows”->“Global Flags”.
3. Select the “Image File” tab.
4. In the “Image: (TAB to refresh)” edit control enter the name of your app then press TAB. Just the name with the extension; not the full path.
5. Tick the following:
- “Enable page heap”
- “Enable heap tail checking”
- “Enable heap free checking”
- “Enable heap parameter checking”
- “Enable heap validation on call”
- “Create user mode stack trace database”
6. Press “Apply”.
7. Debug your application. Any debugger will do but with WinDBG you have access to the stack traces of allocations via the !heap –p –a command, for example. When a heap problem is detected a breakpoint will be generated.
8. When done un-tick all the options you ticked, press “Apply” then dismiss GFlags. This step is important as if it’s skipped all applications named as entered in step 4 will run with the page heap enabled.
Note that when using the page heap your application will run much slower than normal and consume way more memory. It’s good to have a beefy machine to do such tests; and such tests should be ran regularly on all applications you develop as part of regular testing activities. If I find a part of my application that’s too slow with the page heap enabled I optimize the memory allocation in that region.
Steve
|
|
|
|
|
Hey Steve,
I have fixed the issue and it was likely what Matthew mentioned.
Thanks though.
|
|
|
|
|
Please help me.. i need animation which create with Visual C++,
like brush animation or just line can move ... need help plis
|
|
|
|
|
san_sui wrote: animation which create with Visual C++,
Can you more explain?
|
|
|
|
|
i am trying to add the following function as public in my wNode class. my intention is to have a function that returns a two dimensional character array (basically an array of strings and ids)...this is the way i do it:
char[][] getContentArray();
it is giving me a compiler error -> error C3409: empty attribute block is not allowed
what's wrong?
-- modified at 19:19 Friday 15th June, 2007
--
dg
|
|
|
|
|
moonraker928 wrote: char[][] getContentArray();
You'll likely need to use:
char* getContentArray(); or
char** getContentArray();
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
<<<<<<<<<<<< NVM - I GOT IT TO WORK! >>>>>>>>>>>>
still doesnt work..
this is what i have: (i have changed the header file appropriately)
char** workflow::getContentArray()
{
char content[5][5];
return content;
}
error C2440: 'return' : cannot convert from 'char [5][5]' to 'char **' -> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
-- modified at 23:40 Friday 15th June, 2007
--
dg
|
|
|
|
|
moonraker928 wrote: char** workflow::getContentArray()
{
char *content[5][5];
return content;
}
Why would you want to do this? content is no longer valid once getContentArray() goes out of scope. Try:
char* workflow::getContentArray()
{
char content = new char[5][5];
return content;
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am getting this error when I build my project.
error LNK2019: unresolved external symbol __imp__wprintf
I know that means I am linking to the wrong library. I think this is in the runtime library. I've tried the various settings (Multithreaded debug, Multithreaded debug dll) as well as all the other options. Some, of course cause many more errors, none make this one go away.
Please help. Thanks in advance for any advice.
Regards, Bill
|
|
|
|
|
Hi Bill,
I guess, you have "Ignore All Default libraries" option selected. Unselect this option. Go to project settings and choose Link option and uncheck the Ignore All default libraries check box (if you are using VS2003 and above, choose No in the list. The name of the item is same).
Hope that helps.
Kiran.
|
|
|
|
|
Hi Kiran,
Thanks for the reply.
Unfortunately, the developer on this project had already tried that setting:
Ignore All Default Libraries = No.
He also tried changing the Ignore Specific Library setting. He tried setting the ignore list to: LIBCMT;MSVCRTD;LIBC;msvcrt and received a large volume of errors. Also clearing the list resulted in errors. He finally reverted to the original list: MSVCRTD
If you have any more thoughts, I would appreciate hearing from you again. We are starting to fall behind on the project over this issue.
Thanks, Bill
Regards, Bill
|
|
|
|
|
hi all..
i want to write a class for which a private data member is an instance of that same class..
for example:
class wNode {
private:
wNode next;
wNode previous;
...
}
this should be a very standard thing to do - i can do it in java just fine. in c++, it gives me compiler error c2460.
how do i go around this or fix this to accomplish my goal??
thanks!
dg
--
dg
|
|
|
|
|
Define a pointer to the class, not an actual instance. That's what Java does even if the notation may confuse you to think otherwise.
class wNode {
private:
wNode* next;
wNode* previous;
...
}
|
|
|
|
|
|
Where are they?
I don't see them in VS2005's VC/PlatformSDK/gdiplusgraphics.h or elsewhere.
The DrawImage() version documented in their page isn't there either...
http://msdn2.microsoft.com/en-us/library/ms536058.aspx
DrawImage(Image *image, RectF *sourceRect, Matrix *xForm, Effect *effect, ImageAttributes *imageAttributes,Unit *srcUnit);
|
|
|
|
|
|
What is Authenticated user and and what is he allowed to do?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
The Authenticated User is in effect the user who is logged on in term of the pasrticular software of connection in use. In other words when you log on to Windows you are the authenticated user for Windows. This user can do whatevers their permissions and group membership allow then to do dubject to the policies det up by the Administrator,
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Thanks!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Please help me do a query based on date.
I have m_pSet (a pointer to CRecordset) and a filter m_strFilter
my date is a ColeDateTime in the form of "mm/dd/yyyy"
I need to set: m-pSet->m_strFilter to select records with birthday=1/1/1970
Any ideas.
Paulo
|
|
|
|
|
What does your filter string look like?
What does the code look like that constructs it?
Also what does the code look like that executes the query?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hello again board, thanks for answering my previous question. I never programmed for linux. I have about 10 programs(all of them have some sort of data acquisition) developed using MFC for win 98 and XP.recently I've been asked to provide linux versions of these softwares. Is it possible to convert them(each program is relatively big with ~20-30 classes)?
|
|
|
|
|
Since MFC are, by design, a thin wrapper around Win32, they are strictly tied to Windows hence you have to do a lot of work (of course it depends on how much is windowed is your application).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|