Is vector bloated?
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
it takes up lots of memory
-----------------------------------------------------------"People who usualy use the word pedantic usualy are pedantic!"-me
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
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
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
But folks whinned and I had to change it.
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.
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.
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
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
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
But folks whinned and I had to change it.
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
-=Lohrno
May 05, 2002 08:35 PM
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.
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…)
Write a custom allocator and be done with it.
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!
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
-=Lohrno
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...
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement