[RESOLVED] Vector reserving memory, vs linked list
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] Vector reserving memory, vs linked list

  1. #1
    Join Date
    Nov 2007
    Posts
    20

    [RESOLVED] Vector reserving memory, vs linked list

    Hey all,

    due to the generic nature of what I am searching for I am finding it difficult to google my question so sorry if it seems obvious.

    When a vector is initialised it creates a space in memory, if reserve is used it will reserve enough for X elements.

    Does this mean then, that somewhere in memory you will need a chunk of X*NumBytes of unused space to allocate?

    What I am trying to get at is, if you were working on a system with limited memory would it be better to use a linked list because you can allocate memory all over the place and point to it as opposed to needing a chunk in one place?

    That is my perception so far, please do correct me if that is wrong.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,357

    Re: Vector reserving memory, vs linked list

    Quote Originally Posted by nixius
    Does this mean then, that somewhere in memory you will need a chunk of X*NumBytes of unused space to allocate?
    Yes, you would.

    Quote Originally Posted by nixius
    What I am trying to get at is, if you were working on a system with limited memory would it be better to use a linked list because you can allocate memory all over the place and point to it as opposed to needing a chunk in one place?
    I think that you still have to consider the complexity of the operations. Also, if the objects that are stored are not very large, then the additional overhead of book keeping for a linked list might become significant in comparison to a vector. Perhaps a deque would be a compromise, where you want similiar complexity as the operations of a vector, but also want smaller chunks of memory to be allocated, which is the typical implementation of a deque (a doubly linked list of blocks).
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Nov 2007
    Posts
    20

    Re: Vector reserving memory, vs linked list

    Perhaps a deque would be a compromise
    Thanks, I will look into Deque, it is something I have never actually studied.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center