Q: so is there any major advantage from using the vector class vs. using your own resizable dynamic array... (other than having prewritten/readily available code)
Q: so is there any major advantage from using the vector class vs. using your own resizable dynamic array... (other than having prewritten/readily available code)
Last edited by The Brain; 12-15-2004 at 05:11 PM.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
A: Yes there is.
Last edited by Thantos; 12-15-2004 at 05:21 PM.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
Sure change the question on me after I already answered. Of course the answer is still the same. Now can you guess what the smarter question would have been?
where is the love?
Last edited by The Brain; 12-15-2004 at 07:23 PM.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
Chances are good that your STL vector implementation has been tested and used by thousands of programmers, versus your own dynamic array, which is likely to be much less robust.
The STL vector is so common that anybody who looks at, uses or modifies your code will very likely understand it from the beginning, versus your own dynamic array, which they will have to learn.
The people who implemented the STL vector are most likely better at what they do than you are, so their version is probably safer, faster, and more robust than yours.
The only potential major advantage I can think of for using your own version would be if there were specific optimizations that you could implement that could not be implemented with a vector and create a significant performance gain for your app.
I was thinking that there would potentially be a great advantage from making your dynamic array application specific.. since vectors typically allocate memory exponentially.. and from an optimization perspective.. greatly enhance execution time by eliminating the inclusion of unecessary libraries.. (thus eliminating about a bazillion functions you would never use)The only potential major advantage I can think of for using your own version would be if there were specific optimizations that you could implement that could not be implemented with a vector and create a significant performance gain for your app.
Last edited by The Brain; 12-15-2004 at 05:59 PM.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
You can customize the way a vector (or any other STL container) allocates memory. I have done this before and I am pretty sure it would be easier than writing your own complete dynamic array solution.Originally Posted by The Brain
Execution time shouldn't be affected by the number of libraries or functions you use. Maybe executable size, but the difference would be negligible I would think, and they would certainly not outweigh the advantages I mentioned above.
Except for possibly taking a little longer to load the executable into memory, having all those extra functions that are never used would not impact performance speed of the program at all. As for optimizing the functions that ARE called, the likelihood that you will be able to write more efficient functions than the hundreds/thousands/lots of people who have already given input on them is not very high, except in the case where you will *ONLY* be using a specialized subset of what the container will do for very specific purposes that could not possibly have been anticipated for a general robust container class.Originally Posted by The Brain
Well this is what I am thinking....
vector memory allocation:
|---|-----|--------|------------------|-------------------------------|----------------------------------------------------------------|
vs. a fixed incremental memory allocation:
|--------------|--------------|--------------|--------------|--------------|--------------|
in just 6 memory allocations, one can see a significant reduction in allocated memory.. I think one has to weigh the cost between memory allocation vs. execution time to resize the array. Is there a right or wrong anwer? yes. The answer is application specific.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
You can customize the allocation for a vector... it can be pretty much however you want it.
Last edited by jlou; 12-15-2004 at 06:37 PM.
is STL still STL if it has been 'enhanced' by the programmer
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
Umm, yes, very much so. STL was designed to be enhancable by the programmer. It is a feature (which happens to be a major advantage over most in-house implementations ).
so standard template library was designed to become non-standard.. at least at the user level.. (which is cool I think as the programmer annotates the change) thanks for the intellectual discussion everyone. It makes my brain happy.STL was designed to be enhancable by the programmer.
Last edited by The Brain; 12-15-2004 at 07:39 PM.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
>>I think one has to weigh the cost between memory allocation vs. execution time to resize the array.
I'd just like to point out, typically there will be far more memory for you to waste than execution time, especially when writing games
It isn't nonstandard, you're just not using the defaults As far as I know, the difference is just a call to a mode-switching function.so standard template library was designed to become non-standard.. at least at the user level..
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.