|
I was wondering how many people base their error trapping on try and catch? I read in "Game Programming Gems" that exception handling was "expensive" and I wanted to know if anyone has felt this impact? I am writing a multi-client nonblocking telnet server app and speed can turn into an issue. Would I be better off to do a tradition bool or int error returns? Any input would rock!
----
Xian
|
|
|
|
|
Game programming and "normal app" programming are entirely different animals. Games are all about speed, speed, and more speed. When you write something like a Telnet app, most of your cycles will be spent waiting for the user to do something, or waiting for data to arrive via the connection.
I personally use return values for errors. It's what I'm used to and I would gain nothing by using exceptions. MHO of course.
--Mike--
http://home.inreach.com/mdunn/
#include "witty_sig.h"
your with and
|
|
|
|
|
try/catch is not expensive if it's used for unrecoverable errors. At that point you're exiting from the game anyhow. Unreal used exception handling and it's a high performance FPS. try/catch is only expensive if it's used to catch normally occuring errors.
Todd Smith
|
|
|
|
|
No text
----
Xian
|
|
|
|
|
In addition to the other replies, the "expense" of exception handling greatly depends on how it is (mis)used.
For example, wrapping your entire application's code with a single try/catch is not too expensive. But wrapping every single call to "recv(...)" or "send(...)" or every time you process a window messages (if you have a message pump) might be.
Peace!
-=- James.
|
|
|
|
|
Yeah, my main function looks kinda like this :
XGameObj * pGameObj = new XGameObj();
try
{
pGameObj->initGame();
pGameObj->startListener();
pGameObj->gameLoop();
}
catch( const char * pszError )
{
}
My support functions in my Socket handler throw back errors and if they are
bad then I throw them back to the main loop. Other than that I am not doing much with it. I only throw back to the beginning for irrecoverable errors. I hope this is the "proper" way of doing it. I pretty much just figured it out on my own. I dont try/catch every send and receive, plus this is a console app, so no windows pumps! Every heartbeat the events are fired based on time. Like connections are checked and messages are checked every beat, while updates to the queues may occur every 1 real second, etc. I am pretty much just making it up as I go along
Peace.
|
|
|
|
|
> Yeah, my main function looks kinda like this : [...]
I assume you know this, but without a "catch all" handler, you will not catch things like dereferencing a NULL pointer, or other exceptions.
-=- James.
|
|
|
|
|
I assume you know this, but without a "catch all" handler, you will not catch things like dereferencing a NULL pointer, or other exceptions.
I assume you know this, but SEGV is nothing the C++ exception mechanism would usually handle. It's a Microsoft extension. A C++ exception handler (in the context of the ISO C++ standard) handles C++ exceptions. No more, no less.
/Mike
|
|
|
|
|
The astute reader will notice that I did not (nor did anyone else, for that matter) specifically mention "Segmentation Violation", or anything else even close to Unix.
-=- James.
|
|
|
|
|
I always use CDatabase and CRecordset when I am doing windows programming. I was wondering if there is an ADO class that you can use with MFC and whether there is a simple example of it somewhere?
thanks
|
|
|
|
|
There's one here AFAIK. I just #import and use it directly myself.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
There might be a lot of wrapper classes for ADO's raw interfaces.
but it's so easy to use ado with three or more interfaces - _RecordsetPtr, _ConnectionPtr, _CommandPtr. Just make a SQL query string And open recordset , that's all.
|
|
|
|
|
I am programatically changing the font smoothing type in WindowsXP. In WindowsXP there are there settings: no font smoothing, standard font smoothing, and ClearType font smoothing. After diggin into MSDN I found that font smoothing can be set by calling
SystemParametersInfo(SPI_SETFONTSMOOTHING, TRUE, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
I can enable font smoothing, disable font smoothing, and set font smoothing to ClearType.
I can not change the font smoothing mode to standard or change the smoothing contrast. I followed exactly as MSDN instructs but they fail. The MSDN article can be found here.
[edit]
Using GetLastError() it gives the error "The parameter is incorrect."
I am using
SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 1600, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
copied staight from the MSDN article and I'm using the latest PlaformSDK.
[/edit]
And thanks goes out to Nish for steering me in the right direction. The SPIF_SENDCHANGE parameter actually tells it to send a WM_SETTINGCHANGE message.
Joshua
|
|
|
|
|
I am writing a program that was working fine until I added one more variable. Instead of 2 char* I now have three. Each char* is allocated using the new operator and a size of 524,920. Everything works fine until I put in that third variable. Now I get a dynamic memory overrun error, even when I don't touch the data.
Any Ideas?
Thanks in advance,
Clint
|
|
|
|
|
I've read there is a 64k dynamic allocation limit on arrays.
----
Xian
|
|
|
|
|
I'm not sure if this coincide with what you need...
I needed a buffer for file manipulation. The "new" seemed to be limited to 64k of memory. A work around this uses structures. Declare a structure with elements (in my case, BYTE) as array of size 0xff (65,535). If you need more than 64k of memory, declare more array of BYTE's. In order to use it, declare a variable of the structure and a pointer to BYTE. Then point the pointer to the first element of the structure, and voila!, you have a buffer array of more than 64k! Just use the pointer to access the buffer. (elements declared in a structure are allocated continously).
Note: if elements are of size 0xff each, I noticed that one can not have more than 16 elements. Ofcourse, I might be wrong.
typedef struct BUFFER {
BYTE Buffer0 [0xff];
BYTE Buffer1 [0xff];
...
BYTE BufferN [0xff];
} BUFFER;
void Some_Function ()
{
BUFFER Buffer;
BYTE *pBuffer;
pBuffer = Buffer.Buffer0;
memset (pBuffer, 0, <size_of_the total="" array="" of="" buffer="">);
...
}
|
|
|
|
|
Just vondering why you don't use malloc() instead.
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Well from the CRT source code it looks like malloc was using from the dynamic heap. I looked into the heap size and it can't be bigger than about 500k. I ended up just saving that precious heap and used GlobalAlloc instead.
|
|
|
|
|
It uses memory from the global heap. It's no problem to alloc 50MB with malloc()
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Yo.
How can I paint on a CDialog wnd a *.gif picture, without using CHtmlView.
I want *.gif cause' I can use pics with transparent bkgrnd.
(I know howTo with *.bmp, that's not the case)
10x in advance,
\/*** Bar-Cochva ***\/
|
|
|
|
|
You'll need GDI+ or a third party library to use gif, and if you do, beware the evil Unisys license. Otherwise, the MSDN explains how to do transparency masking on the fly, I have an article up at the WDJ site on how to do it as well, or if you're not targetting W95 you can use TransparentBlt ( you'll need do download the SDK if you don't have it ).
If you use GDI+, you don't need GIF, it also has transparent drawing built in.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
What's the proper way of assigning a STL string value to an MFC CString or vice versa? Can you do that?
|
|
|
|
|
CString str;
std::string x;
str = x .c_str ();
x = (LPCTSTR) str;
That should work.
|
|
|
|
|
CString mfcStr;
string stlStr;
mfcStr = stlStr.c_str;
stlStr = /*(LPCTSTR)*/mfcStr;
*** Alphose from OZ ***
|
|
|
|
|
Hi,
I am newbie writing a small SHAREWARE program.
I want to control my software with time limts.(Ex: 30 days, or 2 weeks or Turn off some features after 30 days)
How to accomplish that?
I appreaciate any information regarding this.
thanks
Ravi
|
|
|
|