Thread: Performance Q: Iterate or aggregate pointers?

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    16

    Performance Q: Iterate or aggregate pointers?

    Hello.
    Say I have a thousand instances of a structure, and some of these may be linked to each other due to some criteria that is used on action A.
    Upon running action A for one of these structs, would it be better performance-wise to iterate through the thousand looking for (if any) are linked OR to possess a array in each struct that'd hold the pointers to its linked entities (if any), in a manner iterating through the thousand would not be necessary as it'd iterate through that array and then push the linked entities to perform the action.
    Question is: Which is better? Iterating or aggregating the pointers to the linked entities?
    Thank you for your time.
    Last edited by Hennet; 09-19-2011 at 04:55 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do you have more ram or processor time? If memory isn't an issue, then you can trade off some memory for saving some CPU time. If you need to conserve memory, and have CPU cycles to spare, that's the way to go.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    16
    Thank you for your response.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I would suggest you profile it, to find out where the issue(s) really are.

    That is, before committing several days/weeks to another round of design + code + debugging + testing to implement your "idea", only to find that it doesn't noticeably make anything better.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: aggregate '' has incomplete type and cannot be defined.
    By tommantonela in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2009, 02:50 PM
  2. ERROR: aggregate has incomplete type and cannot be defined
    By jutirain in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2008, 08:24 PM
  3. Something about aggregate type, apparently.
    By Helix in forum C++ Programming
    Replies: 2
    Last Post: 08-02-2003, 02:39 PM
  4. non-aggregate type ??
    By qwerty in forum C++ Programming
    Replies: 1
    Last Post: 05-16-2003, 12:47 PM
  5. non-aggregate data, whats all that about?
    By boothy56 in forum C++ Programming
    Replies: 4
    Last Post: 09-22-2001, 08:54 AM