STL Vector overhead

Can anybody tell me what the overhead of using a STL vector template is. For example if I create a vector using a char*
 
std::vector<char*> status_list;
 
and then I set the list to be 10 items long and initialise each pointer to point to a 256 character string how much memory would actually be used up?
 
e.g.
 
for (int x=0;x<10;x++)
{
  char* empty = new char [256];
  strcpy(empty,"Not Used");
  status_list.push_back(empty);

 
something like this maybe: (256*10)+(sizeof(char*)*10) + overhead?
 
What I am eventually trying to achieve is a list which has x spaces all allocated at the start of the program that I can then copy strings into when "things" happen in my program. Like a debug list that can tell me if anything was out of sequence. When I reach the end of the list I will start back at the beginning, but I need to decide how much memory I am prepared to give over to the list before it will overwrite itself.
 
Would it be better just to use an array:
 
char status_list[MAX_ITEMS][256]?

sdjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yonatCommented:
This is very implementation dependent. In the MS STL, I think that each vector, in addition to the space used to store its elements, has 3 pointers (beginning of storage, end of storage, last element).

Also, for each T, the use vector<T> causes an allocation of space by allocator<T>. You can prevent/change this by using your own allocator.

As for using push_back(), most STL implementation will double the size of the vector storage whenever you call push_back AND there is no more available storage. You can avoid this by calling reserve(N).

In any case, whatever the result you come up with, it will be non-portable and may change  when you use a different/newer STL implementation.
0
altenaCommented:
ping pong... Correct answer by yonat... Give him an "A"
0
nietodCommented:
Sdj. For the exampe you proposed at the end (debug data list?) I would not use a vector.  Vector's are used when you need an array that can be resized.  or elements can be added, deleted, or moved around.  It seems to me that you indicated that you wanedt to allicate an array of a fixed number of elements and not change the number.  That sounds like a job for a plain old array.  (Although a vector would have onslightly more memory overhead over the array in this case.  Especially since you don't resize it.)
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

GregLCommented:
One additional point.  In most implementations the vector uses an array internally, the three pointers are just locations within that array.  I saw this in the Stroustrup book.
0
sdjAuthor Commented:
I'd love to award some points here but until somebody answers the question... (that is answers rather than adds a comment, because I can't grade comments.)

Incidently I now have to have a list whose size is decided at runtime, rather than knowing the size at compile time. That wasn't initially a requirement but know it is I guess I will have to use a list of sometype. I believe vector is still the best option.
0
nietodCommented:
If you need to decide the list size at runtime, but not resize it after that, then a dynamically allocated array might be better than an vector.  (I say might because a vactor has some convenient functions that you might want to have and accept the extra overhead (negligable) for the conveneince)  If you need to resize it, a vector is probably best.  

I would think that yonat deserves the points.  
0
yonatCommented:
Thanks for being gracious, guys. I guess this is one of those "I which I could split the points among several experts" cases.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.