Presentation is loading. Please wait.

Presentation is loading. Please wait.

CRT Topics (Part II) Mahmoud Saleh Windows C++ Team.

Similar presentations


Presentation on theme: "CRT Topics (Part II) Mahmoud Saleh Windows C++ Team."— Presentation transcript:

1 CRT Topics (Part II) Mahmoud Saleh Windows C++ Team

2 FILE IO Buffered vs low-level IO functions – fopen vs open open() maps 1:1 to O/S calls, same thing with _read()/_write(). These maps to CreateFile(), ReadFile() and WriteFile(). No extra buffering by the CRT. Buffered I/O create a buffer for the file data. Few other differences, in terms of standards compliance and dealing with text mode

3 Controlling the stream buffer By default the buffer size is 4K You can assign your own buffer, or even no buffering: – Use setvbuf()

4 GS handler, exceptions, etc… With the compiler support, the CRT has some components of the exception handling and GS cookie support implementation

5 GS cookie handling When a buffer overrun is detected, the GS cookie report handler is executed. By default, the GS cookie handler will allow breaking into the debugger if connected. Ultimately, the application will need to be terminated. /RTC – if enabled, will detect some of the buffer overruns.

6 How C++ exceptions work try{} catch{} is a Compiler/CRT/User code shared effort. Internally uses the exception handling mechanism provided in Windows; e.g. RaiseException C++ unhandled exceptions – terminate() handler

7 CRT and Windows APIs CRT implements standards Still, needs to rely on the O/S for the actual implementation. As seen in the prev examples Visual C++ CRT vs. Windows CRT – Use the Visual C++’s in your applications; currently msvcr100.dll (or libcmt.lib). Each version is tested and guaranteed to run on the O/S it supports; e.g. v.10 supports XP SP2 and SP3, Server 2003 SP1 & SP2, Vista, Server 2008 & R2 and Windows 7. – Windows CRT, msvcrt.dll, is a Windows component specific to the version it runs on.

8 CRT floating point support Uses available architecture, e.g. Math Coprocessor or SSE2. Optimized for the platform it’s running on, x86, x64, … Also, affected by the /fp flag: – /fp:[precise | except[-] | fast | strict ] – Or, use #pragma(float_control, …) Floating point exceptions don’t cause a C++ exception, but rather, an SEH exception, though we can map it to C++ exceptions if we need to. Using _set_se_translator() CRT function to handle floating point exceptions. Suggested reading: Microsoft Visual C++ Floating-Point OptimizationMicrosoft Visual C++ Floating-Point Optimization


Download ppt "CRT Topics (Part II) Mahmoud Saleh Windows C++ Team."

Similar presentations


Ads by Google