|
-
Nov 13th, 2002, 02:33 PM
#1
Thread Starter
Stuck in the 80s
Drowning in Vectors
Okay. I just learned how to use vectors. And now I'm addicted. I have like 10 in my project right now, and I'm wondering if that's too many?
Do vectors use a lot of memory? Do they clean themselves up? Is there something special I should do to clean up the vectors at the end of my program.
Thanks.
-
Nov 13th, 2002, 02:59 PM
#2
They clean them up themselves. And they have only little overhead over the size of the data they actually contain. So unless it's just a hello world app 10 vectors is not too much.
But you should still think for every single vector: "Do I need this dynamic?". The vector class is really nice, but there's no excuse for using a vector for a static array.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 13th, 2002, 03:02 PM
#3
Thread Starter
Stuck in the 80s
The reason I'm using them to begin with is that I created a sub to make increase the size of a dynamic array, then posted it here to get feedback on how I was doing it, and the feedback was "use a vector."
I just happened to have 4 or 5 dynamic arrays and changed them to vectors.
So if I ask myself "do I really need this one?" I can't really answer unless I know that it's the best way to do it.
-
Nov 13th, 2002, 03:06 PM
#4
Frenzied Member
After the first instance of a class is declared & used the overhead is a lot less for each subsequent instance of the same class object.
So, ten is only too many if can't keep track of them or you really don't need them.
One of the things I do is to make existing code faster. As a side effect, it usually means way fewer lines of code. If you pass data back and forth between unnecessary variables it adds overhead as well as increasing complexity (probability of failure goes up).
It's your call
-
Nov 13th, 2002, 03:24 PM
#5
Nothing wrong with converting dynamic arrays to vectors. But do you need them dynamic?
How large is your project? If it's a real app you write alone (small to medium project size) 10 vectors is not much. If it's some uni assignment (tiny project size) 10 dynamic arrays should make you wonder if your approach to the problem is good.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 13th, 2002, 05:27 PM
#6
Thread Starter
Stuck in the 80s
Thanks, guys.
I'm pretty sure I need them dynamic. My program calls for the user to be able to enter stock info, and I want them to enter however many stocks they please, from 1 to however many stocks there are.
-
Nov 13th, 2002, 05:33 PM
#7
Frenzied Member
FWIW - the C99 standard supports dynamic arrays in a bass-ackwards way.
They are called variable length arrays.
Code:
void f(int dimension1, int dimension2){
char whatever[dimension1][dimension2];
}
-
Nov 13th, 2002, 07:24 PM
#8
Junior Member
Maybe i should get around to learning more about C++, this stuff sounds kinda cool.
-
Nov 13th, 2002, 08:02 PM
#9
Thread Starter
Stuck in the 80s
Originally posted by Zaffir
Maybe i should get around to learning more about C++, this stuff sounds kinda cool.
I just learned about them yesterday. They're pretty sweet.
-
Nov 13th, 2002, 08:28 PM
#10
Frenzied Member
Originally posted by jim mcnamara
FWIW - the C99 standard supports dynamic arrays in a bass-ackwards way.
They are called variable length arrays.
Code:
void f(int dimension1, int dimension2){
char whatever[dimension1][dimension2];
}
That is interesting, Jim. Thanks for the info!
Z.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|