LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-06-2006, 11:17 PM   #1
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Angry What the heck is a corrupted double linked list???


Okay I am really really upset. I am trying to make a garbage collector in my C++ program. I've spent about a month now trying every thing I can to get around the thing about not being able to know if the instance of a class is dynamic or not, because, of course, I can't call delete on a staticly created object.
Since "powerful!" C++ doesn't give you any way of doing this, I've been using ugly macros etc.. just to try and let my garbage collector know whether or not my object is dynamicly cunstructed or not...

Okay, that is only the first part. Now for the second. WHAT DOES THIS MEAN: *** glibc detected *** corrupted double-linked list: 0x00000000006d6070 ***!!???!!!??

There is no information about it on google, and the lovely debugger, of course, as always, says: "it happened somewhere, in ??? function, uuhhhh... or something...". What does this mean? Oh, and incase you wanted to know, C++ also stinks because I really just need to have the damn cunstructor of an object return ITSELF!! so it can be overridden (in case the programmer might need that... say... if the object he wants is already in another "auto-pointer" somewhere... damnit).

In short I am upset because, as usual, there isn't I can't find any good information, and because C++ is contstricted when you actually want to do something powerful!!! Darn it.

// edited by crabboy to remove obscenities

Last edited by crabboy; 02-07-2006 at 08:19 AM.
 
Old 02-07-2006, 12:36 AM   #2
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Man, this is not the place to discharge your expletives. It has been reported...
 
Old 02-07-2006, 08:36 AM   #3
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
The_Nerd: As much as I dislike doing so, your post has been cleaned up. The next time I encounter a post like this the content will not survive as it has in this instance.
 
Old 02-07-2006, 08:46 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,376

Rep: Reputation: 147Reputation: 147
One approach to do what you wanted is to make all constructors private. That way they can not be called directly. You then write a function that will create and return the object for you. This way you know that the object will be created dynamically.
 
Old 02-07-2006, 08:56 AM   #5
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Lets just see how many constructive replies you get.
Link taken from Matir's signature http://www.catb.org/~esr/faqs/smart-questions.html

Quote:
Originally Posted by How To Ask Questions The Smart Way
Courtesy never hurts, and sometimes helps

Be courteous. Use “Please” and “Thanks for your attention” or “Thanks for your consideration”. Make it clear you appreciate the time people spend helping you for free.

To be honest, this isn't as important as (and cannot substitute for) being grammatical, clear, precise and descriptive, avoiding proprietary formats etc.; hackers in general would rather get somewhat brusque but technically sharp bug reports than polite vagueness. (If this puzzles you, remember that we value a question by what it teaches us.)

However, if you've got your technical ducks in a row, politeness does increase your chances of getting a useful answer.

(We must note that the only serious objection we've received from veteran hackers to this HOWTO is with respect to our previous recommendation to use “Thanks in advance”. Some hackers feel this connotes an intention not to thank anybody afterwards. Our recommendation is to either say “Thanks in advance” first and thank respondents afterwards, or express courtesy in a different way, such as by saying “Thanks for your attention” or “Thanks for your consideration”.)
 
Old 02-07-2006, 08:44 PM   #6
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Well, at least I got posts. I just assumed someone would delete it, and then go on their merry way. Anyhow, thanks everyone for informing me how to post... like I didn't know I was breaking rules...

In anycase, yes, I admit I was in a rage, yes I admit it was unnecessary, but it was fun. Even so, I am sorry for anyone I offended. Thanks for the posts, and again, sorry.
 
Old 02-07-2006, 09:10 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,481

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
So did you find the memory corruption causing this error message ?

If not, may be can you port the whole stuff to Java, and let its GC do the job for you ...
 
Old 02-07-2006, 10:23 PM   #8
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Ahh, don't bring that four letter dirty word into the mix. C++ is a great language. Post some code.
 
Old 02-07-2006, 10:48 PM   #9
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 117Reputation: 117
Quote:
Originally Posted by dmail
Lets just see how many constructive replies you get.
Link taken from Matir's signature http://www.catb.org/~esr/faqs/smart-questions.html

First off, I'd like to say I'm glad that someone reads my signature. I'm somewhat impressed to be referred to in a thread I have yet to post in.

To the OP: a code sample would be good, as well as a gdb backtrace. I'd love to try to compile and run your code and see how it works, and hopefully be able to resolve this issue.
 
Old 02-08-2006, 01:47 AM   #10
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,481

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by crabboy
Ahh, don't bring that four letter dirty word into the mix.
I beg to differ, Java would have saved the OP one month and its temper.
Quote:
C++ is a great language
Looks like it isn't when dealing with memory management ...
Quote:
Post some code.
Yes, if it fits ... In all cases, it would be helpful to know what was attempted to figure out the memory corruption cause.
- What compiler(s) is used ?
- On what architecture ?
- Were free tools like Valgrind, Sun's Studio RTC or commercial ones like Purify used to debug the issue ?
 
Old 02-08-2006, 03:10 AM   #11
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,050

Rep: Reputation: 971Reputation: 971Reputation: 971Reputation: 971Reputation: 971Reputation: 971Reputation: 971Reputation: 971
Quote:
Originally Posted by crabboy
Ahh, don't bring that four letter dirty word into the mix.
Yummy - JAVA: write once, run no-where.
Quote:
C++ is a great language.
Hmmmm - that's stretching things a lot.

Guess it goes to prove we all have our own tastes.
 
Old 02-08-2006, 08:42 AM   #12
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 117Reputation: 117
I'm personally rather disappointed with the fact that this thread has degenerated into a Java vs. C++ debate. There are some things that just can't be done in Java, and C++ leaves a lot up to the coder (like C) to get right. Each developer needs to determine what is right on each project. I've worked with C, C++, Java, and several other languages. I like C best, but that doesn't mean I claim it to be superior. Or does it?
 
Old 02-08-2006, 10:32 AM   #13
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
Originally Posted by The_Nerd
Well, at least I got posts. I just assumed someone would delete it, and then go on their merry way. Anyhow, thanks everyone for informing me how to post... like I didn't know I was breaking rules...

In anycase, yes, I admit I was in a rage, yes I admit it was unnecessary, but it was fun. Even so, I am sorry for anyone I offended. Thanks for the posts, and again, sorry.

Ok then, lets look at the problem. You want a garbage collector to delete the objects.
Quote:
Since "powerful!" C++ doesn't give you any way of doing this, I've been using ugly macros etc.. just to try and let my garbage collector know whether or not my object is dynamicly cunstructed or not...
Well how about overloading the new and delete operators or creating a specific new operator for creatings objects rather than variables? You can then record the address of all objects created and by giving a specific delete operator for objects this could then remove the record, thus you can tell if its a live dynamic object.

Last edited by dmail; 02-08-2006 at 10:37 AM.
 
Old 02-08-2006, 11:36 AM   #14
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
doesnt boost offer some sort of garbage collection?
 
Old 02-09-2006, 01:41 AM   #15
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Alrighty, here is the code for the new garbage collector I've written. After my "fit", I stopped programming for a while and just thought it over. Since this garbage collector was going into my 2D engine, which was a rather big project, I decided to make the same thing in a smaller app to build/test it. So, here it is. I normally wouldn't release code like this, since my engine is proprietary, but I feel obligated for having eased my "fit" here. Also, I hope some snippets of code may prove useful to others.

Some pointers:
- You may wonder why I have some very strange looking functions, and lots of static veriables. There is only one reason for this, and that is "the global scope". This garbage collector requires lists. However, I can't have those lists in the global scope, because it is very possible that the object might get created before the list... So, I use static variables in "wrapper" functions (such as DynamicList in object.cpp) to achieve what I want, with no segmentation faults.
- I know you want to tell me really really badly about std::list, just don't! Half my problem with the old GC was std::list always causing some really really bad memory error (SEGV), and having the backtrace be about ten pages long, with half the called functions onknown... in short, std::list is impossible to debug and it is slow. I created my own list class because of this reason, and because I've never liked the std::list. I think it was designed stupid like. Not only that, though I don't have any proof, I think my list class is faster.
- I don't want to use Boost!!! No other library scares me like that one. "Fear comes from misunderstanding" you say? Well, you are right. I don't understand the Boost libraries, and don't really want to. Besides that, I am already linking my 2D engine against too many libraries.
- I don't case about Java. Java is cool and all, but I've started the engine in C++, and I am not gunna scrap everything now just to goto Java because of one or two benifits... uuhhhhggg

Have fun trying to understand my code! Basically, to have an object tracked by the garbage collector, all you have to do is derive any class you want to track from CObjectBase<T>, where T is the class name.

The "auto-pointers" aren't implemented yet, so don't spend hours looking for a reference count variable, it isn't there, yet. Remember, this is just a functioning test!

Finally, here is the link to the code:
http://www.restorides.com/~nerd/gc-test.tar.bz2
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to sort double linked LinkedIndex in c++ nadroj Programming 7 02-02-2006 07:22 PM
linked list + c dilberim82 Programming 5 05-04-2005 11:48 PM
cirular linked list pantera Programming 8 04-21-2005 06:59 AM
book linked list in C jetfreggel Programming 14 03-16-2003 10:52 AM


All times are GMT -5. The time now is 10:54 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration