Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Lohrno

Is vector bloated?

This topic is 5861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I think the title pretty much sums up my question, but I''ll try and be a little more specific. =D Is using STL vectors memory efficient for big lists? Is it optomized? =D -=Lohrno

Share this post


Link to post
Share on other sites
Advertisement
The STL is far more optimized than most if not all the folks on this board could do. The thing to remeber though is that the STL is optimized for SPEED, not size.

And honestly, if you needed to ask this question, writing something even comparable to the STL version of vector is far beyond what your capable of yourself.

Landsknecht

Share this post


Link to post
Share on other sites
Landsknecht, most ppl dont need all the features of STL''s vector object. i rarly use it, i find it to be quite restrictive in how it controls how things are allocated. in some situtaions (ie a text control for instance) i like to allocate in linked chunks (ie planar, and no per line), but still may wish to refer to the memory linearly. while this is slower then a single flat chunk, its is easier to work with, and more efficent then leaving it in the hands of vector. i know you could use muliple vectors to do the same things, but why have two layers of abstraction when only one is needed?

Lohrno, do comapisions to something you write vs vector. if your memory manager works better, then use your own. many times if your requirments are simple or very specilized (ie not generalized) then you can get better performence with a custom memory handler. you definatly get more control, but you also must realize that you will spend time optimizing something you may not have to. most of the time memory mangemnet is not time critical because you will not be allocating nor freeing much memory while the game is running.

Share this post


Link to post
Share on other sites
Good point, I defer.

Before using an STL container, you may want to evaluate the problem a little better. A large portion of the time when people use vector, they might as well use a simple array. And vice-versa. If the number of items in your container are not going to fluctuate, use an array. Vectors are realy only useful when you have no idea how many elements you need and the number of elements is likely to fluctuate.

Another thig to think about. Would a purposely oversized array make it easier on you? Maybe. And you probably wouldn''t realy notice any difference.

Landsknecht

Share this post


Link to post
Share on other sites
Ahhh the vector is quick? =D No, because in some cases, it would be useful to use linked lists, or other such things. But it seems that vector does all that. I mean I CAN write linked lists, and make it so that you can insert something into the middle, but thats kinda a pain in the arse! =D If it''s optomized for speed even better. =D I especially like that you can just kinda put anything in, and it becomes like a linked list, dynamically allocatable, and all. Maybe I wouldnt write something with so many features, but I''d write a simple linked list! =D Anyways, thanks though. =D If it is in fact optomized for speed, I''ll use it I think. =D

-=Lohrno

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Lohrno
I especially like that you can just kinda put anything in, and it becomes like a linked list, dynamically allocatable, and all. Maybe I wouldnt write something with so many features, but I''d write a simple linked list! =D Anyways, thanks though. =D If it is in fact optomized for speed, I''ll use it I think.
[quote]

Write a simple linked list using templates.. Then you have that feature of using your list with different kinds of data structures (ints, floats, classes...)

Share this post


Link to post
Share on other sites
Why if it''s already written? =D I mean I could theoretically just plug my structures into the vector, and out comes a nice little linked list type thing with lots of features, stability, and speed right? =D

-=Lohrno

Share this post


Link to post
Share on other sites
quote:
Original post by Lohrno
I especially like that you can just kinda put anything in, and it becomes like a linked list, dynamically allocatable, and all.


A vector isn''t a linked list. The underlying implementation is usually an array (because it is guaranteed that the elements will be allocated in one continuous block).

If you want a (doubly) linked-list, use std::list.

[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]

Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!