CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    Re: [RESOLVED] exit(): memory leaks?

    Interesting... But for this application I'm looking for direct access and control over pointers, without intermediates. I'll take what you say in account for another app I'm writing, however, where pointers specifics are not so stringent.
    - Buzzyous -

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    Re: [RESOLVED] exit(): memory leaks?

    Quote Originally Posted by Buzzyous View Post
    Code:
    	struct myStr
    	{
    		SomeCustomClass* cst;
    		myStr* next;
    		CString identifier;
    		BOOL enabled;
    		CRect rect;
    	};
    These elemnts are dynamically created with new, and linked each other throug the next pointer, which of course points to the next element of the list.
    You could have saved yourself from doing all of this work by just using std::list.
    Code:
    struct myStr
    {
        CString identifier;
        BOOl enabled;
        CRect rect;
        SomeCustomClass* cst;
    };
    
    std::list<myStr> MyStrList;
    //...
    myStr whatever;
    //...
    MyStrList.push_back(whatever);
    This does all of the work you just described. Not only that, the classes properly destroy themselves. As STLDude mentioned, you need to really investigate the C++ standard library components, boost, and smart pointers.

    C++ is no longer equivalent to coding 'C' with some home-made classes. There is a whole library of container types available that are standard, and far more stable and safter to use than doing this by hand.

    Regards,

    Paul McKenzie

  3. #18
    Join Date
    Apr 1999
    Posts
    27,449

    Re: [RESOLVED] exit(): memory leaks?

    Quote Originally Posted by Buzzyous View Post
    Interesting... But for this application I'm looking for direct access and control over pointers, without intermediates.


    Please explain. Note that the std::list uses pointers internally, and you don't have to deal with them. So I don't know exactly what you're implying.

    If you're saying you can "beat" what std::list does, either in safety or efficiency, that is highly doubtful.

    Regards,

    Paul McKenzie

  4. #19
    Join Date
    Apr 1999
    Posts
    27,449

    Re: [RESOLVED] exit(): memory leaks?

    Also, from your description of what your program is supposed to do, why do you need "direct control" (whatever that means) of pointers? It is a GUI app, and you want to handle a few dialogs -- I see no reason for low-level pointer manipulation.

    Even so, the goal of a C++ programmer is to first write the program so that it works. Once it works, then and only then do you profile the code for any inefficiencies. You don't try to micromanage pointers for a non-working program -- that is a recipe for disaster (or at least, development time that would take 2, 3, maybe 5 times or more the effort than using standard containers, smart pointers, etc.).

    Regards,

    Paul McKenzie

  5. #20
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    Re: [RESOLVED] exit(): memory leaks?

    Of course I am not able, nor I intend, to beat standard containers. Anyway, the struct is just one part of the container I had in the app. The skeleton pointer is a multiple layer list, not just the plain linear you saw. Standard container are fast, useful and reliable, but cannot cover all cases, because they are standard. The list I need are not just linear, but extends in many dimensions and trees. If this can be accomplished with the list std container I am unaware of it and apologize for having wasted your time asking you to help me trying to get my superfluous struct to work, because the problem was the same on all levels of the "hyperlist", about being unable to destroy on exit.

    I recently found out that memory leaks were due to another class, however. Sorry for having wasted your time asking you to correct an already working code.
    - Buzzyous -

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured