What is a Windows equivalent of CppCheck?
Asked Answered
A

1

6

I have an extreme problem.

I have been working on a game for about two years(20000+ lines of code), and Lately I have been noticing a ton of memory leaks. The problem is that I cannot track every single one of them since my game is way too big...

I have searched around and noticed that CppCheck would be useful in my situation, but the problem is that since I am using windows, i cannot use CppCheck(which is for linux only).

I am wondering if maybe there is a library or plugin that is CppCheck's equivalent for windows, or maybe a way to use CppCheck on windows instead.

All of the possibilities that I have come up with, along with solutions to other's problems(such as using smart pointers for std::deque and such) imply that my program is small or the more fitting: rewrite my entire program, something that I -really- do not want to do...

IDE: Code Blocks 10.05

Compiler: MinGW 3.81 GCC 4.4.1

Attestation answered 13/1, 2013 at 22:59 Comment(21)
As other information: I have skills that I use that are the main bottlenecks for the memory leaks(1 hour of extreme combat and the game goes from 100mb to 1.5gb). Other situations are moving from map to map(despawns other NPCs/deletes from vector)Attestation
I used CppCheck. On Windows. I found it to be an open source project in great need of programmers that need to it to be better. Given the alternatives, I didn't see much point in helping out.Pickard
This is why you start with smart pointers, not start with raw pointers and find you need smart pointers after your program is 20000 lines of code.Oreste
Would you happen to know any other programs to find memory leaks? If not then maybe even a library or method to store copies of NPCs for said map(deleting them afterwards)Attestation
@Molma: The trouble with any tool like this is that it's not very precise -- it might be able to catch some memory leaks, but it's very unlikely for it to be able to catch all of them. What I would suggest is another approach: start commenting which pointers in your code own memory, and which ones merely reference it. Take special note of circular references if there are any. Then, one by one, start using shared_ptr, and converting to (owning) pointers using release in order to keep the program compilable. Keep repeating until you get rid of leaks or have no more raw pointers.Ardrey
@SethCarnegie When I first started working on this project, I had no ideas of smart pointers or memory leaks. It was only recently that I have noticed the massive amounts of leaks that my program has(lately I have been bent on increasing speed). I blame this crazy mistake on myself since I am self-taught...Attestation
Also see vld.codeplex.comArdrey
@Molma: It's all a learning experience. :) Just curious, do you use malloc/free in your code a lot, or new and delete?Ardrey
@Mehrdad If it were that simple then I would have started doing that already. My problem against that is the fact that most of my code(centered around the player) would not agree to shared_ptr. The way I have my deques coded are where the player is also added to the list of spawns, this way the skills and other objects can react to it just like any other NPCAttestation
@Molma: That's why I didn't tell you to use shared_ptr everywhere; I said start using it incrementally (starting at wherever you create new objects points), switching to raw pointers when you need to, by releasing the shared_ptr and getting back a raw pointer.Ardrey
@Mehrdad malloc/free I did not know much about, new/delete is what I use for almost every object I have in my game. Im doubting that the problem is with creating objects, I would say its more toward any type of deque storage.Attestation
@Attestation what you need to do is look for every new and find where and when it is deleted in your source. If this really is your first project, it's unreasonable not to expect to rewrite large portions as your knowledge grows.Oreste
@Mehrdad Im pretty sure in the past I have had problems with changing slight bits of deque to shared_ptr. And for some reason, When changing anything to shared_ptr it said that the object's name was not defined, meanwhile it was defined on that exact spot...Attestation
@SethCarnegie: Easier said than done at this point to be fair. That's why it's important to try and avoid memory leaks in the first place.Guest
@Molma: If possible would you mind showing me an example of a few lines that you changed from deque to shared_ptr, which gave an error? It shouldn't be erroring like that.Ardrey
the first error I got was in one of my header files. std::deque<Item*> ItemList to std::deque<std::tr1::shared_ptr<Item>> ItemList. Also I am not sure as to keep Item* when changing to shared_ptrAttestation
@Attestation what compiler are you using? If it's moderately modern, it shouldn't be in the tr1 namespace, just the std namespace.Oreste
@SethCarnegie Im still trying to find that, I have gotten the default install with codeBlocks 10.05, but I am having trouble finding the version for MinGWAttestation
The version is 3.81 MinGW GCC 4.4.1Attestation
There isn't going to be a magic bullet here, you already know the answer (use smart pointers) and anything less than that is going to be a band-aid solution, so I'm not sure what sort of answer you are hoping for here. Perhaps clarify your question with an example piece of code you'd like to avoid rewriting?Wellfound
Alright, after some research I have found some information that should make converting to shared_ptr a bit easier: shared_ptr question. with this I should be able to switch to shared_ptr quickly and without much fail. One question though: When changing to shared_ptr should it be in shared_ptr<Object> format or shared_ptr<Object*> format? with the first I am wondering if that will still work with variables with that type of pointer(e.g. Ogre::SceneNode*), since I use ogre3dAttestation
N
5

CppCheck works on Windows too (check downloads on SourceForge). CppCheck is only a static check tool (it analyzes your source code to find some potential problems). In order to find real memory leaks it may be necessary to use some debugging tool that actually runs your code (look at Google's Dr. Memory for example).

Ngocnguyen answered 13/1, 2013 at 23:14 Comment(1)
I am currently Running my program under Dr. Memory to see If I can get anywhere.Attestation

© 2022 - 2024 — McMap. All rights reserved.