• Welcome to Valhalla Legends Archive.
 

Suggestions for good Advanced C++ Books and/or Websites.

Started by Sorc.Polgara, December 14, 2005, 07:55 AM

Previous topic - Next topic

Sorc.Polgara

So I recently delved into creating my own Dynamic Link Libraries in C++.  However, after compiling my DLL and testing it, I found that I had memory leaks, memory corruption, and was just plain recklessly handling memory.  I believe that most of my problems are a result of the way I programmed my packet buffer class and the sole fact that I'm still new to making DLLs.

So, I've come to the conclusion I need to do some more learning on good programming practices, working with memory, tips, tricks, etc.

I also need to learn more about making DLLs.

Thus, do you know of any good Advanced C++ Books and/or Websites?  Same for books or websites on making DLLs.

Thanks.

EDIT:  Also, do you know of any good C++ help forums?


QwertyMonster

Quote from: Sorc.Polgara on December 14, 2005, 07:55 AM

EDIT:  Also, do you know of any good C++ help forums?

You could try these forums. I'm sure with giving enough detail for help, and having patience, you will resolve most likely, or nearly all of your C++ problems?

MyndFyre

Quote from: Spht on December 14, 2005, 09:00 AM
Quote from: Sorc.Polgara on December 14, 2005, 07:55 AM
EDIT:  Also, do you know of any good C++ help forums?

Ouch.

Seriously!

My thought on your memory leaks is that it's most often caused by allocating pointers and/or buffers and then not keeping track of them enough to free them.  For example, if you're making a packet buffer class, make sure to overload the destructor (that's ~ClassName(optional-parameter-list)) and include the instruction to delete your buffer.  It could also be that you're allocating a pointer in a function and returning it.  While not inherently bad, I tend to discourage that practice in favor of an additional pointer/reference parameter.  So, instead of:

int* getData() {
 int* result = &m_data;
 return result;
}

we rather have:

// if successful, this function returns nonzero.
BOOL getData(int* value) {
 BOOL result = FALSE;
 if (value != NULL) {
   value = m_data;
   result = TRUE;
 }
 return result;
}

That's a lot more verbose, and the example is simplistic, but it avoids pointer allocation.  A common mistake leading to memory leaks is to allocate new pointers and not delete them; in C, this is malloc()/free(); in C++, this is new/delete (or delete[]).

Finally, it seems to me that using a DLL has absolutely nothing to do with whether you'd have memory leaks.  You'd still have memory leaks if you were compiling to an EXE and then using LoadLibrary()/GetProcAddress().
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Adron

Quote from: MyndFyre on December 14, 2005, 10:12 AM
Finally, it seems to me that using a DLL has absolutely nothing to do with whether you'd have memory leaks.  You'd still have memory leaks if you were compiling to an EXE and then using LoadLibrary()/GetProcAddress().

Memory leaks and memory corruption can stem from allocating memory using one run-time library in a DLL and attempting to free it using another run-time library in the EXE calling the DLL.

Sorc.Polgara

#5
Quote from: Spht on December 14, 2005, 09:00 AM
Quote from: Sorc.Polgara on December 14, 2005, 07:55 AM
EDIT:  Also, do you know of any good C++ help forums?

Ouch.
I mean any other C++ forums.  That statement/question was in no manner meant to offend or insult the vL community.  In fact, these are the only programming forums I mainly feel comfortable posting on.  However, I want as much advice as I can get on my packet buffer class, which I posted awhile ago and have since made some improvements, and have already recieved this community's opinions and criticism.

In the past, the vL community has helped me with A LOT of stuff.  I'd rather not repeat myself and post my packet buffer class again... I'd like to take it to another C++ forum that is atleast equivalent in helpfulness as the majority of the vL programming forums.

Yegg

Quote from: Spht on December 14, 2005, 09:00 AM
Quote from: Sorc.Polgara on December 14, 2005, 07:55 AM
EDIT:  Also, do you know of any good C++ help forums?

Ouch.

Other than this site, forums.devshed.com is in my opinion the best one available for most programming language discussion plus many other computer and technology related topics alike.

Kp

Quote from: MyndFyre on December 14, 2005, 10:12 AM
(that's ~ClassName(optional-parameter-list))

Minor nit: destructors don't take parameter lists.  Since destructors for local variables are called automatically at the end of the basic block in which the variable is declared, there's no provision for specifying what arguments the destructor would receive.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!


MyndFyre

Quote from: Kp on December 14, 2005, 02:14 PM
Minor nit: destructors don't take parameter lists.  Since destructors for local variables are called automatically at the end of the basic block in which the variable is declared, there's no provision for specifying what arguments the destructor would receive.

Hrm, I thought for whatever reason that it's possible to specify a parameter to a destroyer when it's explicitly called (which is evidently not possible).

Is a destroyer called when operator delete is invoked?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

Quote from: MyndFyre on December 14, 2005, 04:41 PMIs a destroyer called when operator delete is invoked?

Yes, if one is defined.  Otherwise you'd have different cleanup procedures depending on whether the object was destroyed by end-of-block or by explicit deletion.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!