|
Since Complex is a class, you should probably be using new (and delete ).
simoncoul wrote: const Complex I(0.0L,1.0L); //imaginary numbers
double **I = (double**)malloc(sizeof(double*)*K);
So what is I ?
"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
|
|
|
|
|
This code was produced by someone else, but from my taking on it, it's just a 2D array with 1000 positions. I don't believe that I needs to be complex either, since it is being cast as a double, and no calculations are done with that involve it needing to be complex.
Thank you
|
|
|
|
|
But what is I ? How is the compiler not complaining about a re-definition?
"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 can't tell you why you're getting an erro on h == 2 but I would try something like this instead.
<br />
double** I = new double*[K];<br />
for( int h = 0; h < K; h++ )<br />
{<br />
I[h] = new double[K];<br />
}<br />
Obviously you'll need to do matching deletes, remember to use delete [] , array delete in case you every want to compile this on a non Microsoft system.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I have tried what u said using new instead of malloc, but still when h = 2 in the loop I get an error.
Windows has triggered a breakpoint in kpSim.exe.
This may be due to a corruption of the heap, and indicates a bug in kpSim.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information
and it causes the break in the free.c file.
Thanks
|
|
|
|
|
OK, the clue here is the break is in free.c . My guess from this is that code you posted or I posted is fine and the error is occuring in code I havn't seen yet. free.c is going to be doing a free, which needs changing to a delete, anyway. You need to track down what it is that's being freed and where this call originates from. If you can find the code with the free that is failing and changing it for a delete to match the new doesn't help, post it and I may be able to help. If I've left for the garage by then others will pick it up.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Ok I have looked through the code and found that in some parts new was being used to allocate but free was being used instead of delete. I'm going to go though and fix that up and hopefully that will work. Thanks for the help, I will let you know the results.
|
|
|
|
|
I am still getting an error when h = 2, I have absolutely no idea what is happen as I have fixed all the new/delete problems.
Like the program still functions if I just continue pass the heap error, and every time I run the program after that(until I close VS) I don't get it anymore.
When I trace through the code when the error occurs it happens in files that I have not touched that are part of VS librarys.
|
|
|
|
|
This can happen if you have a memory overrun. If you allocate a buffer and then write beyond the end, or beginning, of it you can damage data belonging to the C Runtime. There used to be a classic example using stdio which blew up spectacularly.
I would be interesting to know if it actually crashes in Release builds. If so you may just be damaging the gaurd bytes inserted between allocations in debug mode. This can happen with a very slight overrun, <= 4 bytes, and you'll get away with it often in debug except for the rude messages from the runtime. In Release it will very likely go bang.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I tried it in the release mode and it is still giving me the error, this makes no sense cause the array is being initialized and allocated in that block of code that I posted earlier, that stuff isn't touched prior to that so I don't see why I'd be having so many problems allocating it. I have tried making using different loops and allocating the memory in different ways but it always messes up at h = 2. Thanks again for all the help.
|
|
|
|
|
I'm very sorry, I just noticed this in the output
HEAP[kpSim.exe]: Heap missing last entry in committed range near 4327310
Windows has triggered a breakpoint in kpSim.exe.
I hope this will help so we can figure out what is going on.
thanks
|
|
|
|
|
Ok, that's wierd. I've never seen that error before. I take it you're not using some kind of alternative heap manager or managed C++? If it's not too long I suggest you post whole thing, or email it to me and I'll have a look. I'll also check the C Runtime sources to see if this is just an unusual error that's been lurking there all the time. Knowing which version of MSVC you're using would help as well
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Did you write past the end of the array (heap)?
|
|
|
|
|
That error is no long happening, it now occurs prior to that block of code when I do:
int K = 1000
Ey_x= new Complex [K];
Ey_z_C=new Complex [K];
Ey_z_L=new Complex [K];
z_prime=new Complex [K];
It occurs at "Ey_z_L=new Complex [K];" but if I rearrange them is will still always occur in the 3rd spot.
Any Ideas??
Thanks
|
|
|
|
|
Sorry I didn't see those messages post before I posted my last one. I am using visual studio 2005, and I do not believe that I am writing outside of the heap. I don't think I can e-mail u the whole code as it is for a program that is IP of the school I am working at but this is the part that is causing me all the problems.
int K=1000;
Complex *Ey_z_C,*Ey_z_L,*Ey_x,*z_prime;
Ey_x= new Complex [K];
Ey_z_C=new Complex [K];
Ey_z_L=new Complex [K];
z_prime=new Complex [K];
double *x_prime;
x_prime=new double [K];
Complex dz;
double n_eff_C = z_dir(dz,z_prime,Ey_z_C,K,N,n0_C,z);
double n_eff_L = z_dir(dz,z_prime,Ey_z_L,K,N,n0_L,z);
double dx;
double n_eff_x=x_dir(dx,x_prime,K,Ey_x,n_eff_C,n_eff_L,w);
Complex **Ey = (Complex**)malloc(sizeof(Complex*)*K);
for ( i =0; i < K; i++){
Ey[i] = (Complex*) malloc(sizeof(Complex)*K);
}
double **I = (double**)malloc(sizeof(double*)*K);
j = 0;
while (j<K){
I[j] = (double*) malloc(sizeof(double)*K);
j++;
}
|
|
|
|
|
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
|
|
|
|
|
I have found the problem, I had a loop that was writing to much data to the allocated space. It was much earlier in the code and that was why it was so hard to track down this bug.
Thanks for all the help everyone!
|
|
|
|
|
I'm trying to implement a "MFC CList look-alike" wrapper on top of the STL list using MS Visual C++ 2005 Express.
The implementation of the iteration methods begin-next-prev-end requires a storage of the position in the class like this:
<br />
#include <list><br />
template< class TYPE> <br />
class CList<br />
{<br />
protected:<br />
std::list< TYPE >::iterator pos;<br />
...<br />
But it doesn't work... I get these compiler errors:
warning C4346: 'std::list< TYPE >::iterator' : dependent name is not a type
error C2146: syntax error : missing ';' before identifier 'pos'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I don't quite understand the errors. Using the same declaration (std::list< TYPE >::iterator p) in a member function, I don't get any errors at all from the compiler.
Why am I not allowed to declare this iterator (pos) as a member in the class? Hope someone can help?
-- modified at 11:45 Tuesday 5th June, 2007
-- modified at 11:46 Tuesday 5th June, 2007
Anton112
|
|
|
|
|
Interesting, as your code snippet compiles fine with VS6.
template<class T>
class CList
{
protected:
std::list<T>::iterator pos;
}; I'd guess that it has to do with VS2005 being more C++ compliant. See here.
"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
|
|
|
|
|
Well, I have to admit that I don't know anything about compilers in that sense. Hence, I don't know anything about differences between specific compilers. In fact, years agy I tried to be a Windows developer, but it is years ago...
Anton112
|
|
|
|
|
iterator cannot be deduced as a type by the compiler. To make it (compiler) think so, put typename in front of its declaration;
template<class T>
class CList{
protected:
typename std::list<T>::iterator pos;
};
--
=====
Arman
|
|
|
|
|
Thanks, Arman
You gave me my answer...
Anton112
|
|
|
|
|
Hello I do not know if this messageboard is the good one !
I have a problem with fonction recev
the code under MFC VS2005
Before I get a connection with accept(...)
rVal = recv(m_acceptSocket,messageStream,BUFFER_SIZE,0);
if ( rVal == 0 || rVal == WSAECONNRESET || rVal==SOCKET_ERROR) {
m_clientConnected=false;
if (rVal==SOCKET_ERROR)
{
int errorCode = 0;
string errorMsg ="error calling recv():\n";
//void detectErrorRecv(int* errCode,string& errMsg)
//{
//*errCode = WSAGetLastError();
//if ( *errCode == WSANOTINITIALISED )
//else if ...
}
detectErrorRecv(&errorCode,errorMsg);
}
}...
My problem is that the error do not match with any error possible for the fonction recev (WSANOTINITIALISED ,WSAEADDRINUSE ,......)
I do not undestand how it his possible.
Thank you for help me !
AutreChien
|
|
|
|
|
NorGUI wrote: My problem is that the error do not match with any error possible for the fonction recev (WSANOTINITIALISED ,WSAEADDRINUSE ,......)
Do you know ALL of the error codes that recv() could return? There are 2000 socket-related codes. What is the value or rVal ?
"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
|
|
|
|
|
recv() doesn't return an error code.
rVal = recv(m_acceptSocket,messageStream,BUFFER_SIZE,0);
if (rVal == SOCKET_ERROR)
{
int nWSAErr = WSAGetLastError();
if (nWSAErr == WSAECONNRESET)
{
}
else if (nWSAErr == ...)
{
}
}
else if (rVal == 0)
{
... the connection has been closed
}
else
{
... bytes were received
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|