|
-
January 12th, 2013, 10:47 AM
#8
Re: Invalid access to memory location using GlobalFree
 Originally Posted by 2kaud
I'm going to rewrite it from the ground up using classes and put all the memory management into the classes where it belongs.
If you are willing to change to C++ and not stick with 'C', I would start out with the small things first. For example, if they coded their own linked list or string handling, replacing those with standard C++ classes that handle these issues. Dynamically allocated pointers usually can be changed to some sort of smart pointer, i.e. shared_ptr, unique_ptr, etc, so that you don't get involved too much in memory management.
Believe it or not, it isn't that difficult to change such a program -- just change one or two definitions to C++ classes, compile the app, fix the expected compile errors, test. That's how I've approached changing large, procedural C++ programs that are coded in a C-like manner (or just straight 'C' programs into C++) into one that is maintainable. In my experience, the threading issues seems to work itself out naturally once the underlying infrastructure is built on a more stable and maintainable foundation. You may find you need less critical sections once the globals or static variables are removed.
Another thing to consider (if you switch to C++) is using RAII to control your critical sections, i.e. you create a class that always unlocks the critical section on destruction if the function or code block exits for any reason whatsoever. To do this in 'C' or non-OO C++ is not easy, but by using classes, becomes very simple.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|