The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ftp zip files corruption colesga Shell Programming and Scripting 3 08-02-2007 08:22 AM
*** glibc detected *** free(): invalid next size (normal): 0x0000000000503e70 *** vbreddy High Level Programming 1 04-11-2006 09:18 AM
NTFS corruption under w2k but not under suse 9.2 mickepe Windows & DOS: Issues & Discussions 4 08-05-2005 05:19 PM
data corruption with ftp transfer malcom UNIX for Advanced & Expert Users 12 08-04-2003 04:38 AM
file corruption shibz UNIX for Advanced & Expert Users 5 09-06-2002 08:56 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8  
Old 05-18-2006
Registered User
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
oh thanks for spotting that. i wrote simple loops just to test it out, but obviously i havent been able to get that far.

that is all the code, the entire header file. it compiles fine with no warnings what so ever.

maybe its my system? id try running it on my server but i dont want to risk bringing that down.

heres a simple driver program, this just hangs, it dosnt even print the message in there that is before the creation of the Dynamicarray objects:

Code:
#include <iostream>
#include <string>

#include "Dynamicarray.h"

using namespace std;

int main()
{
	cout << "before object creation...";
	
	Dynamicarray <int> newArray(5);
	Dynamicarray <string> newArray2;
	
	
	for(int i = 0; i < newArray.size(); i++)
	{
		newArray.add(i);
	}
	
	cout << "newArray with size of 5: " << endl;
	
	for(int i = 0; i < newArray.size(); i++)
	{
		cout << " " << newArray.get_val(i) << " ";
	}
	
	cout << "newArray2 with type string, undefined size: " << endl;
	
	string s1 = "using";
	string s2 = "my";
	string s3 = "dynamic";
	string s4 = "array..";
	string s5 = "with templates";
			
	newArray2.add(s1);
	newArray2.add(s2);
	newArray2.add(s3);
	newArray2.add(s4);
	newArray2.add(s5);
	
	for(int i = 0; i < newArray2.size(); i++)
	{
		cout<< " " << newArray2.get_val(i) << " ";
	}
	
}
Reply With Quote
Forum Sponsor
  #9  
Old 05-19-2006
Registered User
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
well i wrote another class using templates to see if there was something i was doing wrong there, and thats not the problem. im going to have to rework the Dynamicarray code all together.
Reply With Quote
  #10  
Old 05-19-2006
Registered User
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
alright well it seems that the problem isnt a problem with code, if i leave the class declaration and implementation in a cpp file with main() it works fine, if i put the class deff and imp in a .h and include it that way, thats when it simply dosnt work, the program hangs, or during certain conditions ill get the glibc detected double free or corruption error.

anyone know why this is?
Reply With Quote
  #11  
Old 05-19-2006
Registered User
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
i am aware that when using templates that you must keep the definition and declaration in the same file, but as for what file it must be in i thought could be any.
Reply With Quote
  #12  
Old 05-19-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 979
I dunno. If you can't track down exactly where the crash is happening, it'll be very hard to tell anything... can you compile it with the '-ggdb' flag, then run it like this:
Code:
gdb ./program
gdb prompt> run
crash error message
gdb prompt> bt f
full backtrace printout
gdb prompt> quit
I also notice that, since you're using cout, your messages aren't necessarily getting printed when you think they are -- it buffers. If it crashes before the buffer is flushed, it won't get printed, even if the cout call happened first. Even explicit flushing doesn't seem to help that on some systems. Try fprintf instead:
Code:
#include <stdio.h>

...

fprintf(stderr,"printf example:  c-str %s, int %i, ptr %p, float %f char %c\n",
    "c-string", 42, (void *)(0xdeadbeef), 3.14159, 'q');
stderr never buffers.

It also helps in debugging that fprintf is one single function call, while cout is as many function calls as there are << paramaters...

Last edited by Corona688; 05-19-2006 at 10:56 PM.
Reply With Quote
  #13  
Old 05-24-2006
Registered User
 

Join Date: May 2006
Location: Ames, IA
Posts: 9
*** glibc detected *** double free or corruption (top): 0x08ec9a48 ***

I'm a C++ beginner programmer. I'm using C++ on Unix with the gcc version 3.4.5 20051201 (Red Hat 3.4.5-2).

I have the same error message with my simulation program. When this error happens then the simulation stops running with the message "Abort".

The simulation is supposed to run 50 replicates. This problem occurs randomly. Sometimes, it happened in the 32th and 37th replicates. Other time, it happened in the 3rd replicate.

So, I tried to debug the program by running the program step by step. Surprisingly, the program ran fine. No error.

Or when I tried to run the replicate that had this problem, then it ran fine, too. But not with 50 replicates in a row.

My friend told me maybe it had something to do with optimization. I even lowered the level of optimization from -O to -O0. It didn't help.

Could somebody educate me what is going on? Where should I look at?

Many thanks.
Reply With Quote
  #14  
Old 05-24-2006
Registered User
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
youll have to post the code where the problem occurs, if you can determine where that is.

in my case, (i havent solved the problem yet) it seems like my system dosnt like templates in header files. my code runs fine with no problems if i have the class declared and implemented in the same file as main().
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0