|
In this case it looks like something is wrong with the heap. Maybe to heap has been corrupted. While it's possible the machine is at fault it's hard to imaging it would boot with such a serious fault.
Steve
|
|
|
|
|
Stephen Hewitt wrote: In this case it looks like something is wrong with the heap. Maybe to heap has been corrupted.
Yes, maybe, but I have no real idea on how to set a good value, or if I should use RESERVED or VALIDATE. Any explanation about that would be great!
|
|
|
|
|
Firstly did you try the double * const a ? If the pointers are meant to point at the same object for the life time of the pointer but you want to be able to change the object pointed to this is how you should declare the pointer anyway.
Secondly, to check for heap corruption, you could try enabling the page heap for the process. Follow these steps.
1. Download WinDBG from here[^].
2. Install it.
3. From the start menu select “Start->All Programs->Debugging Tools for Windows->Global Flags”.
4. Select the “Verifier” tab.
5. In the “Image: (TAB to refresh)” edit control type the name of your EXE. e.g. For notepad you’d enter “notepad.exe”.
6. Press “TAB”.
7. Tick the “Enable” and “PageHeap” check boxes.
8. Press “Apply” and “OK”.
9. Debug you application. It will run many times slower than normal and consume heaps more memory than is normal – Don’t panic.
When you’ve found the memory error go through the steps again (not steps 1 and 2) but in step 7 uncheck all the tick boxes – This is important or your application will run slow and eat memory forever on your machine (and so will any EXE with the same name).
Steve
Steve
|
|
|
|
|
Out of interest, what are the values of Nb and Nc?
Steve S
Developer for hire
|
|
|
|
|
What's the actual number of allocation, eg. how many doubles do you want?
A very simple change (but not very smart, just to get an insight into what's happening) are to just do one allocation (as the number of doubles are constant)
<br />
double* base=(double*)malloc(N*3*sizeof(double));<br />
double* a=base + 0 * N;<br />
dobule* b=base + 1 * N;<br />
double* c=base + 2 * N;<br />
Why are you using malloc/free instead of new[]/delete[]?
Whenever I've runned into a memory problem, the cause of the problem was often totally unrelated to the symptoms. Eg. your code is probably working but sometimes before coming there, you have a memory error (out of range access, failed allocation).
Good hunting
-- modified at 7:40 Friday 21st July, 2006
|
|
|
|
|
Steve S wrote: Out of interest, what are the values of Nb and Nc?
Nb and Nc are similar. Actually Nb = Nc = grid->n_rad (grid is a class). The real code is:
double *temp_radiale = (double*)calloc(grid->n_rad,sizeof(double));
double *delta_temp_radiale = (double*)calloc(grid->n_rad,sizeof(double));
double *avg_rad_energy = (double*)calloc(grid->n_rad,sizeof(double));
The code runs fine when I change some parameters which actually change the overall allocated memory of my code (although not the n_rad value mentioned above). I'm not too familiar with HEAP and STACK, so could that be such an issue? (I've also tried to increase dramatically these HEAP and STACK values, but nothing changed).
-Lyu
|
|
|
|
|
Jonas Hammarberg wrote: Whenever I've runned into a memory problem, the cause of the problem was often totally unrelated to the symptoms.
Same here.
Steve
|
|
|
|
|
I tried to use the new and delete operators without success.
I will try several things before posting again. Thanks for all your comments and talk to you later!
|
|
|
|
|
Follow the steps I posted here[^]. If you've got heap corruption the last thing you want to do is poke around the edges until you "solve" the problem: it's there lurking until you find the cause and you're lucky you can reproduce it so easily.
Steve
|
|
|
|
|
Hi!
I left the debugging problem for later on, because my code ran fine when I changed the parameters (it has to deal with the size of many arrays, but it does not necessarily crash when I increase these sizes). Anyway, I just realized that I forgot to mention that the code is crashing only in the "release" executable, and runs fine in debug mode. Also, one important thing is that I use either an AMD machine (desktop for simulations) or an Intel proc (laptop) for coding and debugging. The release exe sometimes runs fine on the Intel, but crash on the AMD.
This being said, I should say that I'm not familiar with debugging tools (like WinDbg) apart fom the Visual debugger. But it's not of big help if the code only crashes in the release exe.
Anyone could give me a hint to start? (Sorry Steve, although you detailed the process to do it, I'm afraid I'm missing somthing at some point )
|
|
|
|
|
lyuabe wrote: This being said, I should say that I'm not familiar with debugging tools (like WinDbg) apart fom the Visual debugger. But it's not of big help if the code only crashes in the release exe.
I gave detailed step by step instructions. Debugging tools (such as WinDBG) work almost as well on release builds as they do on debug builds as long you build the release build with debugging info (.PDB files).
Steve
|
|
|
|
|
Hi Steve,
Stephen Hewitt wrote: as long you build the release build with debugging info (.PDB files)
Yes, but I did not know how to make WinDbg use the PDB file. First I tried to use PDB from the debug version, but of course it does not work. And actually I did not know that it's possible to generate the debug info for the release, so thanks very much for the info!!... so I just found the option to generate the debug info file PDB for the release executable. Okay, I'll try this and tell you the results of the process... Thanks again!
|
|
|
|
|
Remember to enable the debug info for the compiler and the linker.
On MSVC6 follow these steps on your release build:
1. Select "Project->Settings..."
2. Select "C/C++" tab.
3. In the "Category:" combo select "General".
4. In the "Debug info:" combo select "Program Database". We don't use the edit and continue option in a release build.
5. Select the "Link" tab.
6. In the "Category:" combo select "Debug".
7. In the "Debig Info" group tick "Debug info", "Microsoft format" and "Seperate types".
If your using a later version you'll have to adapt these steps.
Steve
|
|
|
|
|
Hi,
I generated the debug info (PDB file) for my release exe. But when I use it on the simulation computer with WinDbg, it keeps on saying:
*** ERROR: Symbol file could not be found. Default...
although I specified the "symbol file path" to be the correct one (I think). What am I doing wrong?
...and you were right, because windbg indicates:
HEAP[FMCT.exe]: Invalid allocation size - AC1905B4 (exceeds 7ffdefff)
But I do not know where that is without the trace of the code...
|
|
|
|
|
First locate the .PDB file. It should be in the same directoy as the .EXEs in. Enter the path of the directory that contains it in the symbol file path. You shouldn't need to do this however. Are you sure you've got the PDBs?
Steve
|
|
|
|
|
Stephen Hewitt wrote: You shouldn't need to do this however. Are you sure you've got the PDBs?
Yes I'm sure. But here the exact configuration I use: first I compile the code on my laptop (Intel proc) with all the compiling options you mentioned for debugging (although I could not find any option in .NET 2003 for the "Microsoft format" and "Seperate types" for debugging info). Then I copy the EXE and PDB files on the AMD machine and run WinDbg on the AMD: I launch WinDbg, set the symbol file path, then use the command Open Executable and select my EXE, and specifiy the running directory of my EXE (which is different from the location of the PDB file). Is there something wrong in what I'm doing?
Thanks again.
|
|
|
|
|
Hi there,
That's it, I fixed it. Actually, I was mislead by the first debugger comment when opening the EXE. It said that it could not locate the SYMBOL info, but later when it crashed, it correctly reported the error using the PDB (and source code?) I put in the Symbol folder.
Okay, thanks very much for your help. I hope next time I have a crash in my RELEASE I will be able to find the exact reason... althgouh now I've chanegd my code to run in Multi-Thread ... so debugging is even more complicated.
By the way I have a question about multi-threading, are you familiar with it?
-Lyu ABE
|
|
|
|
|
Somewhat....What's your question?
Steve
|
|
|
|
|
Humm.. I was about to ask why one of my two threads was finishing the job much before the other (they are performing the same task, but on separate memory spaces, so no lag due to access to shared ressources). Then I realized it was because I used a (stupid) while to wait for some bool flags in each thread to be set to true, and the laggy thread was running on the same core than the main program. That's why it was slown down. Now I'm using Events to signal the state of the thread, using CreateEvent , SetEvent and ResetEvent . I have the same crashing issue on the AMD proc . It runs fine on the Intel laptop, but crashes on the AMD (both with RELEASE EXEs). (if you have suggestions, they are welcome...)
Anyway, I am now wondering if these multithread functions _beginthread , etc. are portable to other platforms (i.e. is that standard C++)??
|
|
|
|
|
I found why the code crashed on the AMD machine: it is because I got this strange crashing issue (the origin of my message). But now what is puzzling me is that when I use WinDbg to launch the EXE, it runs fine, but when I use console command, it crashes . Any explanation to that?
|
|
|
|
|
Okay, I guess I've found the cause of the crash: I was not freeing some (small) arrays in one of my subroutines... However, it seems strange to me that it made my code crash. I thought that if it was not freed, then the memory space was just allocated and not available to other allocation during the code execution...
Anyway, I got it solved, so I'm happy
Thanks all for your suggestions to this thread.
Lyu ABE
|
|
|
|
|
Hi,
Can u please help me to solve the problem.
I have two property pages in a property sheet.
The first one is CCmpListSetupDlg
and the second one is CCmpDataEntryDlg.
In the first propertypage i am getting a string into the variable "str".
BOOL CCmpListSetupDlg::OnKillActive()
{
CString str;
// I used CListCtrl two create grid lines and when user click on a row(item)
// i am getting the text value into the CString variable "str"
CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_LISTITEMS);
POSITION pos = pListCtrl->GetFirstSelectedItemPosition();
if (pos == NULL)
{
AfxMessageBox("No items were selected!\n");
}
else
{
while (pos)
{
nItem = pListCtrl->GetNextSelectedItem(pos);
str=pListCtrl->GetItemText(nItem,0);
AfxMessageBox(str);
return CPropertyPage::OnKillActive();
}
}
}
//This is my second property page
//When ever my second property page is activated i want the text
//value of "str" to get displayed .
BOOL CCmpDataEntryDlg::OnSetActive()
{
AfxMessageBox("Hi Dataentry page is active");
// here str value should be displayed.
return CPropertyPage::OnSetActive();
}
Thanks in Advance.
|
|
|
|
|
tejaswini.g wrote: AfxMessageBox("Hi Dataentry page is active");
// here str value should be displayed.
return CPropertyPage::OnSetActive();
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
tejaswini.g wrote: AfxMessageBox("Hi Dataentry page is active");
// here str value should be displayed.
return CPropertyPage::OnSetActive();
is CPropertyPage* CPropertySheet::GetPage(int nPage) of any help!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Can u show me please How can I use it in my program.
|
|
|
|