CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 18

Threaded View

  1. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Linked List issue / debugging

    Quote Originally Posted by ghostfacelz View Post
    Hmm.. that does sound like it could have worked better (or at least made things easier).
    Yes. Basically, when the std::list class wants to create a new node or remove a node, it calls an "allocate"/"deallocate" function from that template you see as the second parameter. The list doesn't care how that template is implemented, except it must be a well defined interface (the allocator interface, which you can google easily to see what's required).

    So replacing that template with your own template, and then creating your own allocate() and deallocate() function, would probably have done the trick (given that you know how to use the memory pool you have and return what list is requesting).

    All of those other functions that link previous nodes with next nodes and checking for NULL, etc. -- there is no need for that as the std::list does that for you already. So basically, you would have used std::list to do the "list" work, and your allocator to do the work of supplying the memory for the node data.

    If maybe you have a few minutes to spare, would you mind taking a look at the code if I emailed it to you? its not huge (about 500 lines, but mostly due to switch cases and if's because of the 7 lists).
    You could just zip it up and post it here as an attachment, along with the project (no obj, ncb, or any of those unnecessary files -- only enough to load and compile the project).

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; May 14th, 2011 at 03:57 PM.

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