[QUOTE=high;18891415]..exception stuff..[/QUOTE]
Huge stack to unwind there.
[QUOTE=high;18891415]
You are missing the point.. It already is doing bounds checking, what is the point of you doing bounds checking.[/QUOTE]
Well, that macro up there only sets the fail-bit if the length >= the size, so I suspected that I can just check the length beforehand.
For other kind of errors I'd create temporary values, read all in, check for fail-bits and if set, print an error and return (global values don't get modified), if not, set the global stuff to the temporary values.
[QUOTE=BlackPhoenix;18891450]Good idea, but how do you go about variable-sized structures?[/QUOTE]
operator sizeof can handle that ^_^
[QUOTE=ZeekyHBomb;18891761]Huge stack to unwind there.
[/QUOTE]
Does this suffice?
[cpp]std::exception* ex;
void CallStacky( int num )
{
if (num == 1000)
return;
CallStacky(num + 1);
}
int _tmain(int argc, _TCHAR* argv[])
{
ex = new std::exception("test");
LARGE_INTEGER start;
QueryPerformanceCounter(&start);
ULONGLONG start2 = GetTickCount();
for(int i = 0; i < 1000;)
{
try
{
CallStacky(0);
i++;
}
catch (std::exception* e)
{
i++;
}
}
ULONGLONG end2 = GetTickCount();
LARGE_INTEGER end;
QueryPerformanceCounter(&end);
end.HighPart -= start.HighPart;
end.LowPart -= start.LowPart;
end2 -= start2;
std::cout << "High: " << end.HighPart << std::endl;
std::cout << "Low: " << end.LowPart << std::endl << std::endl;
std::cout << "MS: " << end2 << std::endl;
std::cin.get();
return 0;
}
[/cpp]
Cause it is actually faster to throw the exception then to return from the 1000 calls :P.
Also changed it to
[cpp]void CallStacky( int num )
{
char test[0x1000];
for(int i = 0; i < 0x1000; i++)
{
test[i] = (char)i;
}
if (num == 100)
throw ex;
CallStacky(num + 1);
}[/cpp]
Still faster to throw the exception :P.
[quote]AnimationEditor has encountered a problem and needs to close. We are sorry for the inconvenience.[/quote]
Upon startup. I wanna see that cool facepunch figure!
[QUOTE=high;18892009]Does this suffice?
[cpp]std::exception* ex;
void CallStacky( int num )
{
if (num == 1000)
return;
CallStacky(num + 1);
}
int _tmain(int argc, _TCHAR* argv[])
{
ex = new std::exception("test");
LARGE_INTEGER start;
QueryPerformanceCounter(&start);
ULONGLONG start2 = GetTickCount();
for(int i = 0; i < 1000;)
{
try
{
CallStacky(0);
i++;
}
catch (std::exception* e)
{
i++;
}
}
ULONGLONG end2 = GetTickCount();
LARGE_INTEGER end;
QueryPerformanceCounter(&end);
end.HighPart -= start.HighPart;
end.LowPart -= start.LowPart;
end2 -= start2;
std::cout << "High: " << end.HighPart << std::endl;
std::cout << "Low: " << end.LowPart << std::endl << std::endl;
std::cout << "MS: " << end2 << std::endl;
std::cin.get();
return 0;
}
[/cpp]
Cause it is actually faster to throw the exception then to return from the 1000 calls :P.[/QUOTE]
You're not even throwing an exception there :downs:
You just don't understand exceptions, that's all. Don't worry, with more experience with different libraries you'll start to understand.
Exceptional code isn't meant to continue along its original path, thus making it exceptional. That's why when you throw an exception, it reaches the nearest catch block. If some data file is completely necessary and continuing without it would be impossible, then it not existing is indeed an exceptional case. However, if it's a simple media file, that the user might not have, then it would not be an exceptional case, and therefore, the code can continue along its normal path.
[QUOTE=nullsquared;18892221]You're not even throwing an exception there :downs:
You just don't understand exceptions, that's all. Don't worry, with more experience with different libraries you'll start to understand.
Exceptional code isn't meant to continue along its original path, thus making it exceptional. That's why when you throw an exception, it reaches the nearest catch block. If some data file is completely necessary and continuing without it would be impossible, then it not existing is indeed an exceptional case. However, if it's a simple media file, that the user might not have, then it would not be an exceptional case, and therefore, the code can continue along its normal path.[/QUOTE]
Replace the "return" with "throw ex".
[QUOTE=high;18892009]
[cpp]void CallStacky( int num )
{
char test[0x1000];
for(int i = 0; i < 0x1000; i++)
{
test[i] = (char)i;
}
if (num == 100)
throw ex;
CallStacky(num + 1);
}[/cpp]
Still faster to throw the exception :P.[/QUOTE]
Your stupid tests don't prove anything at all. Regardless of how many nanoseconds an exception might take, it jumps to the nearest catch block, because the state is exceptional and cannot continue along with the current code.
Try this one
[cpp]
void DoSomething( i )
{
if ( i == 10 )
throw ex;
blahblah here;
}
void CallStacky( int num )
{
float* f = new float;
for (int i=0; i<100; i++
DoSomething( i );
delete f;
} [/cpp]
Oops leaked memory because I code stupid
Are you sure about your timing?
[url]http://stackoverflow.com/questions/567579/how-expensive-are-exceptions[/url]
[url]http://stackoverflow.com/questions/1018800/performance-of-c0x-exceptions[/url]
[media]http://www.youtube.com/watch?v=C9Q9YyqQOjg[/media]
Testing extrapolation for multiplayer. Red crosses are where pedestrians were located in last frame received from server, green crosses are where pedestrians are located on local client (and after extrapolation), red lines connect these two points.
You can see that it works almost exactly precisely - just sometimes resyncing. But high pings mean that other players [b]will[/b] be very laggy, and your gameplay will degrade (unless you're just walking around - as you can see, AI peds are extrapolated very nicely).
The data rate is about 4kb/sec, it's that high because it doesn't use delta compression, instead transfers positions and data about all 11 pedestrians on screen, no compression or delta compression.
[QUOTE=garry;18892606]Oops leaked memory because I code stupid[/QUOTE]
That example breaks if you're an average or above coder and use smart pointers.
high, just accept it. Your code is shit
[QUOTE=garry;18892606]Try this one
[cpp]
void DoSomething( i )
{
if ( i == 10 )
throw ex;
blahblah here;
}
void CallStacky( int num )
{
float* f = new float;
for (int i=0; i<100; i++
DoSomething( i );
delete f;
} [/cpp]
Oops leaked memory because I code stupid[/QUOTE]
This. Plus, as I said, exceptions are for exceptional conditions, where code should not continue along its normal path. Performance does not come into play at all.
[QUOTE=ZeekyHBomb;18892653]Are you sure about your timing?
[url]http://stackoverflow.com/questions/567579/how-expensive-are-exceptions[/url]
[url]http://stackoverflow.com/questions/1018800/performance-of-c0x-exceptions[/url][/QUOTE]
He used a different compiler. I am using MSVC.
Anyways, you shouldn't be throwing exceptions for everything. Only things that interrupt the programs flow. Like winsock failing to connect.
[QUOTE=turby;18892801]high, just accept it. Your code is shit[/QUOTE]
All high said was he didn't like a certain part of C++, if he was wrong about what he thought then it's as simple as that.
High makes quite a lot of programs and posts quite a lot of content. As for you, I haven't really seen anything you've made, which leads me to believe that you are in no position to critisise high.
You haven't produced any shit which was impressive and all you are doing is acting like a catalyst in the argument here. Shame on you people who rated him agree.
If you are just going to flame and stir shit up then get the fuck out.
Did a bit more on the editor today. Didn't get much done because I had to help my sister move house and code the tree control..
[img]http://filesmelt.com/downloader/12Dec2009_001.png[/img]
[QUOTE=garry;18892606]Try this one
[cpp]
void DoSomething( i )
{
if ( i == 10 )
throw ex;
blahblah here;
}
void CallStacky( int num )
{
float* f = new float;
for (int i=0; i<100; i++
DoSomething( i );
delete f;
} [/cpp]
Oops leaked memory because I code stupid[/QUOTE]
When you implement exceptions you should account for this. Also why wouldn't you use a smart pointer for that?
Anyways, it is pointless to continue this argument. You guys can stick with your old C style of returning error codes and error functions.
You mean the method that is 700% times faster
[QUOTE=high;18894751]Anyways, it is pointless to continue this argument. You guys can stick with your old C style of returning error codes and error functions.[/QUOTE]
You're implying they never use exceptions when it's time to. Maybe you should consider that there's a time to use error codes and there's a time for exceptions?
[QUOTE=gparent;18894819]You're implying they never use exceptions when it's time to. Maybe you should consider that there's a time to use error codes and there's a time for exceptions?[/QUOTE]
Ya, when you are coding C.
[QUOTE=garry;18894798]You mean the method that is 700% times faster[/QUOTE]
4 instructions is so much to execute! The only time it slows down is when the exception is actually thrown and even then it isn't much(eventually those local deconstructors were going to be called anyways...).
How long have you been coding in c++ because you're obviously more experienced than all the experienced programmers in this thread telling you not to use exceptions so liberally
[QUOTE=high;18894863]Ya, when you are coding C.[/QUOTE]
Or C++. It depends on the design, not what language you're using.
[QUOTE=garry;18894932]How long have you been coding in c++ because you're obviously more experienced than all the experienced programmers in this thread telling you not to use exceptions so liberally[/QUOTE]
Guess that's what happens when you spend your time trying to reverse shit instead of actually coding it.
[QUOTE=garry;18894932]How long have you been coding in c++ because you're obviously more experienced than all the experienced programmers in this thread telling you not to use exceptions so liberally[/QUOTE]
Cause ignoring a useful feature of C++ makes you an amazing coder!
No, it makes me a productive programmer
[QUOTE=high;18895050]Cause ignoring a useful feature of C++ makes you an amazing coder![/QUOTE]
Do you use doubles to count to 3 too?
[QUOTE=garry;18895109]No, it makes me a productive programmer[/QUOTE]
So you still using C then? Fuck that, use assembly!
[QUOTE=high;18895050]Cause ignoring a useful feature of C++ makes you an amazing coder![/QUOTE]
[QUOTE=high;18893984]
[b]Anyways, you shouldn't be throwing exceptions for everything. Only things that interrupt the programs flow.[/b] Like winsock failing to connect.[/QUOTE]
:downsbravo:
I am going to end up repeating myself. So I am done. Have fun with your C code.
WinSock failing to connect is a horrible example of an exceptional case.
Exceptions are not for things that [I]always[/I] warrant checking for error.
[QUOTE=high;18895246]Have fun with your C code.[/QUOTE]
That must be the reason exceptions are used so sparingly in the C++ standard library!
A quick question :
What's better, C# and XNA
orrrr
C++ and some 2D engine
?
I had this crazy thought of remaking my game in c++ before it's too late =)
Sorry, you need to Log In to post a reply to this thread.