Valhalla Legends Forums Archive | General Programming | Suggestions for good Advanced C++ Books and/or Websites.

AuthorMessageTime
bethra
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?
December 14, 2005, 1:55 PM
Spht
[quote author=Sorc.Polgara link=topic=13514.msg137596#msg137596 date=1134568505]
EDIT:  Also, do you know of any good C++ help forums?
[/quote]

Ouch.
December 14, 2005, 3:00 PM
QwertyMonster
[quote author=Sorc.Polgara link=topic=13514.msg137596#msg137596 date=1134568505]

EDIT:  Also, do you know of any good C++ help forums?
[/quote]

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?
December 14, 2005, 4:08 PM
Myndfyr
[quote author=Spht link=topic=13514.msg137597#msg137597 date=1134572420]
[quote author=Sorc.Polgara link=topic=13514.msg137596#msg137596 date=1134568505]
EDIT:  Also, do you know of any good C++ help forums?
[/quote]

Ouch.
[/quote]

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:
[code]
int* getData() {
 int* result = &m_data;
 return result;
}
[/code]
we rather have:
[code]
// if successful, this function returns nonzero.
BOOL getData(int* value) {
 BOOL result = FALSE;
 if (value != NULL) {
   value = m_data;
   result = TRUE;
 }
 return result;
}
[/code]
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().
December 14, 2005, 4:12 PM
Adron
[quote author=MyndFyre link=topic=13514.msg137606#msg137606 date=1134576756]
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().
[/quote]

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.
December 14, 2005, 5:59 PM
bethra
[quote author=Spht link=topic=13514.msg137597#msg137597 date=1134572420]
[quote author=Sorc.Polgara link=topic=13514.msg137596#msg137596 date=1134568505]
EDIT:  Also, do you know of any good C++ help forums?
[/quote]

Ouch.
[/quote]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.
December 14, 2005, 6:32 PM
Yegg
[quote author=Spht link=topic=13514.msg137597#msg137597 date=1134572420]
[quote author=Sorc.Polgara link=topic=13514.msg137596#msg137596 date=1134568505]
EDIT:  Also, do you know of any good C++ help forums?
[/quote]

Ouch.
[/quote]

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.
December 14, 2005, 8:07 PM
Kp
[quote author=MyndFyre link=topic=13514.msg137606#msg137606 date=1134576756]
(that's ~ClassName(optional-parameter-list))[/quote]

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.
December 14, 2005, 8:14 PM
K
[quote author=Sorc.Polgara link=topic=13514.msg137627#msg137627 date=1134585170]
I mean any other C++ forums....
[/quote]

Shameless Plug.
December 14, 2005, 8:14 PM
Myndfyr
[quote author=Kp link=topic=13514.msg137653#msg137653 date=1134591268]
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.
[/quote]

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?
December 14, 2005, 10:41 PM
Kp
[quote author=MyndFyre link=topic=13514.msg137677#msg137677 date=1134600107]Is a destroyer called when operator delete is invoked?[/quote]

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.
December 14, 2005, 11:58 PM

Search