This is very untrue, and your whole post is based around this argument.Quote:
Originally Posted by dcjr84
It shuld be initialised. But not by vector. By user. having an array of 0's is also garbage.
Printable View
This is very untrue, and your whole post is based around this argument.Quote:
Originally Posted by dcjr84
It shuld be initialised. But not by vector. By user. having an array of 0's is also garbage.
... so you just created million 10's while you only need the number 10, good job.Quote:
Originally Posted by laserlight
If the user writes:Quote:
It shuld be initialised. But not by vector. By user. having an array of 0's is also garbage.
Then the user is creating a vector of a million 0s. It is as simple as that. What the user requests be done surely cannot be garbage.Code:std::vector<int> x(1000000);
If I only need the number 10 stored in a variable, I would write:Quote:
... so you just created million 10's while you only need the number 10, good job.
If I needed an int vector with a capacity of million elements, the first of which I currently know to be 10, I would write:Code:int x = 10;
The above vector only has a size of 1, and rightly so since only 1 int is what I need at the moment.Code:std::vector<int> x;
x.reserve(1000000);
x.push_back(10);
This is, frankly, much ado about nothing.
you know im not going to discuss anymore, if you guys dont even want to try think my position fine, stay one minded. :)
dcjr84
I disagree with your reasoning. Having initialized values is important, but not because it allows sloppy code to work. In your case you better should have array initialized to something like minimum possible value of integer to show error right when it occurs. Having consistent result guarantees repeatability of error behaviour.
Vectors, and especially arrays, should always be
initialized. period. Doesn't matter if its by the user or done
automatically by it's implementation. The performance impact is
negligible.
And even if it did reduce performance; I would rather
have a program that runs at 50% speed but is guaranteed to
an extremely high percentage to never make a mistake
in calculation because it might at some point use an unintialized
garbage value from an array or vector, than have one that runs
at 100% speed but the results might be incorrect at some point
because there is the possibility it might use an uninitialized element
from an array or vector.
yes i very agree. but in my opinion this is a user fault not an array object fault.Quote:
Originally Posted by RoboTact
More generally, nondetermenistic behaviour shouldn't be exposed. If said uninitialized value lurks shot within object and isn't visible outside it, fine, as far as object itself works right.Quote:
Originally Posted by dcjr84
This is an programmers fault in this case. And will not happen in good desgined software. Doesnt mather if it is a vector or not having 0's is still garbage and will get wrong calculations if software is not rightly designed. Besides arrays are almost never used for calculations, but mostly for storing objects for games. POD's for images, files etc.Quote:
Originally Posted by dcjr84
Using vector will only decrease performance, and if this is not visible, the cpu cycles will waiste energy, and decrease computer's life time.
There is no fault in question, is there? ;)Quote:
Originally Posted by Mitsukai
:eek:Quote:
Originally Posted by Mitsukai
You should reconsider level of conviction in such assertions.
I guess i late in game now :)
The sicussion went somewhere else than original post. though first i agree with Paul we need to find out how these timing taken.
>>yes i very agree. but in my opinion this is a user fault not an array object fault.
The evolution of all programming language is based on easy to use & hard to make mistkes by "user". There no need to use C++. We can do all things in C & assembly. Lets imagine handling memory managment in C for all the objects than using C'tor & D'tor. "user" is more likely to make the mistakes in C. In think there is no harm in providing automatic initilation to some value rather than having uninitiliaze. I bet for most of the application the overhead is very very less.
Vinod
But, if you use vector::reserve, then it does create an uninitialised array. It's just that you can't randomly access the values until you put something in it, and then only the values that you've added. This is a good thing. Plus, as has already been pointed out to you, your "vector replacement" is seriously flawed.Quote:
Originally Posted by aewarnick
Again, this is negligible. Hundreds if not thousands of cpu cycles areQuote:
Using vector will only decrease performance, and if this is not visible, the cpu cycles will waiste energy, and decrease computer's life time.
probably wasted every minute of every day by your computer for a
multitude of reasons: bad CPU scheduler decisions, etc, etc. I highly
doubt that using a vector is going to decrease your computers lifetime
by so much that it would even be noticeable.