CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2013
    Posts
    2

    Ideas for avoiding reallocation costs when inputs are unbounded

    Something that I have thought about for a while and have not been satisfied with my ideas is how to handle reallocation costs when input data is unbounded.

    For instance, in a low-latency environment such as a trading platform or real-time data collection system or MMORPG where you can receive a large amount of input, you can not afford a stall while the data structure is rebuilt with a larger buffer. You can use historical data to "guess" an appropriate size but this is far from fool-proof. You can also create a sentinel thread that monitors the load factor of your data structure but that brings its own problems (e.g. another thread that needs execution time and to lock the data).

    Can anyone recommend schemes they've seen that work?

    Incidentally, I posted this question on SO and was accused of cheating on a homework or interview assignment. I am not in school and am not interviewing. This is a nagging question I am finally getting around to posting on a forum for input.

    Thanks

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Ideas for avoiding reallocation costs when inputs are unbounded

    Schemes i've seen (and some I used)...

    1) don't worry about it
    2) allocate the max you can possibly need. any attempt to go above this is a hard error.
    3) don't use containers that need reallocation
    4) write your containers yourself in such a way that reallocation isn't an issue within the bounds of your system demands.
    5) upgrade to faster hardware so software performance issues aren't present
    6) change the system demands to allow for higher latency
    7) redesign your app to not need any containers that couldl be so large that reallocation could be an issue.
    8) change your container to pointers to objects instead of holding objects (copying pointers is faster than copying objects).

    there's probably more...

    there's no one size fits all solution, the default containers are all "good generic solutions", but specialized needs require specialized solutions. All of the above can work, neither is best or "the go to solution" for all cases where reallocation is an issue. Know what you're doing and why you're doing it. All of the above have advantages and disadvantages.

    As a general rule, if you have a situation where reallocation is an issue, you probably have a boatload of other performance issues to tackle as well.

  3. #3
    Join Date
    Jul 2013
    Posts
    2

    Re: Ideas for avoiding reallocation costs when inputs are unbounded

    Thanks for the response. Good info.

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