LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What the heck is a corrupted double linked list??? (https://www.linuxquestions.org/questions/programming-9/what-the-heck-is-a-corrupted-double-linked-list-412457/)

The_Nerd 02-06-2006 11:17 PM

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

primo 02-07-2006 12:36 AM

Man, this is not the place to discharge your expletives. It has been reported...

crabboy 02-07-2006 08:36 AM

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.

graemef 02-07-2006 08:46 AM

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.

dmail 02-07-2006 08:56 AM

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”.)


The_Nerd 02-07-2006 08:44 PM

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.

jlliagre 02-07-2006 09:10 PM

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 ...

crabboy 02-07-2006 10:23 PM

Ahh, don't bring that four letter dirty word into the mix. C++ is a great language. Post some code.

Matir 02-07-2006 10:48 PM

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.

jlliagre 02-08-2006 01:47 AM

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 ?

syg00 02-08-2006 03:10 AM

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.

Matir 02-08-2006 08:42 AM

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? :)

dmail 02-08-2006 10:32 AM

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.

xhi 02-08-2006 11:36 AM

doesnt boost offer some sort of garbage collection?

The_Nerd 02-09-2006 01:41 AM

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


All times are GMT -5. The time now is 03:48 PM.