Click here to Skip to main content
15,913,773 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralTemplate issue Pin
Bob Stanneveld15-Sep-04 10:32
Bob Stanneveld15-Sep-04 10:32 
GeneralRe: Template issue Pin
Michael Dunn15-Sep-04 10:48
sitebuilderMichael Dunn15-Sep-04 10:48 
GeneralRe: Template issue Pin
Bob Stanneveld15-Sep-04 11:10
Bob Stanneveld15-Sep-04 11:10 
GeneralProtect application from hooking Pin
Fabio Panzavolta15-Sep-04 10:01
Fabio Panzavolta15-Sep-04 10:01 
GeneralRe: Protect application from hooking Pin
User 58385215-Sep-04 15:55
User 58385215-Sep-04 15:55 
GeneralRe: Protect application from hooking Pin
Fabio Panzavolta15-Sep-04 22:47
Fabio Panzavolta15-Sep-04 22:47 
GeneralCost of type Casting Pin
Nacho Chip15-Sep-04 9:59
Nacho Chip15-Sep-04 9:59 
GeneralRe: Cost of type Casting Pin
Andrew Walker15-Sep-04 13:02
Andrew Walker15-Sep-04 13:02 
The authoratative source on all things performance in C++ is:

C++ Standards Committee Performance TR[^]

From the performance TR:
const_cast<Type>(expression) // §IS-5.2.11
static_cast<Type>(expression) // §IS-5.2.9
reinterpret_cast<Type>(expression) // §IS-5.2.10
dynamic_cast<Type>(expression) // §IS-5.2.7

The first three forms of type conversion operator have no size or speed penalty versus the equivalent cast notation. Indeed, it is typical for a compiler to transform cast notation into one of the other type conversion operators when generating object code. However, dynamic_cast<t> may incur some overhead at run-time if the required conversion involves using RTTI mechanisms such as cross-casting (§2.3.8).

The report goes on to give examples of how dynamic cast costs are dependant on the types you are casting to and from. If you believe casting to be an issue profile your application and compare the cost of the cast to the rest of the application.

Casting is not likely to be significant performance cost in the bigger picture unless you do it very often - in which case the design may require refactoring. There are however, two conflicting opinions on the use of dynamic casts. One is that it is best to avoid dynamic casting where possible through the use of the visitor pattern (Design Patterns - Gamma, Helm et al.), and the other is that the use of dynamic_casts elminates the need for large ammounts of code that the visitor pattern requires.

Nish's Excellant article on Casting Basics[^]


If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts your aim;
Yours is the Earth and everything that's in it.

Rudyard Kipling

GeneralSearching Image inside the Bitmap Pin
Azghar Hussain15-Sep-04 9:17
professionalAzghar Hussain15-Sep-04 9:17 
GeneralRe: Searching Image inside the Bitmap Pin
David Crow15-Sep-04 9:35
David Crow15-Sep-04 9:35 
GeneralRe: Searching Image inside the Bitmap Pin
Alexander M.,16-Sep-04 9:56
Alexander M.,16-Sep-04 9:56 
GeneralExtract an ISO File To the Local disk Pin
ntuyen0115-Sep-04 9:16
ntuyen0115-Sep-04 9:16 
GeneralRe: Extract an ISO File To the Local disk Pin
David Crow15-Sep-04 9:33
David Crow15-Sep-04 9:33 
GeneralRe: Extract an ISO File To the Local disk Pin
ntuyen0115-Sep-04 10:02
ntuyen0115-Sep-04 10:02 
GeneralRe: Extract an ISO File To the Local disk Pin
David Crow15-Sep-04 10:08
David Crow15-Sep-04 10:08 
GeneralRe: Extract an ISO File To the Local disk Pin
ntuyen0115-Sep-04 10:13
ntuyen0115-Sep-04 10:13 
GeneralRe: Extract an ISO File To the Local disk Pin
David Crow15-Sep-04 10:41
David Crow15-Sep-04 10:41 
GeneralRe: Extract an ISO File To the Local disk Pin
ntuyen0115-Sep-04 11:27
ntuyen0115-Sep-04 11:27 
GeneralRe: Extract an ISO File To the Local disk Pin
David Crow16-Sep-04 3:00
David Crow16-Sep-04 3:00 
GeneralRe: Extract an ISO File To the Local disk Pin
Alexander M.,16-Sep-04 10:00
Alexander M.,16-Sep-04 10:00 
GeneralRe: Extract an ISO File To the Local disk Pin
David Crow16-Sep-04 10:20
David Crow16-Sep-04 10:20 
GeneralRe: Extract an ISO File To the Local disk Pin
Henry miller15-Sep-04 10:39
Henry miller15-Sep-04 10:39 
GeneralRe: Extract an ISO File To the Local disk Pin
ntuyen0115-Sep-04 11:26
ntuyen0115-Sep-04 11:26 
GeneralRe: Extract an ISO File To the Local disk Pin
cmk15-Sep-04 19:46
cmk15-Sep-04 19:46 
QuestionGain SuperCapture of the mouse? Pin
DaFrawg15-Sep-04 8:40
DaFrawg15-Sep-04 8:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.