Notes and issues taken down in practice.
Define Functions with Macro
- Macro Definition Example
1 | // Windows SDK (winnt) |
- Usage Example
1 | STDMETHOD(get_Count)(_Out_ long* pcount) |
Operator Overloading
1 | struct Sum |
In this table, @ is a placeholder representing all matching operators: all prefix operators in @a, all postfix operators other than -> in a@, all infix operators other than = in a@b
Summplement:
Within the namespace (e.g. in other member functions of the same class), we can use in this way;
1 | this->operator()(item); |
Notice the differences among size_t
, UINT
, UINT64
, etc.
1 | // Defined by compiler |
Since memcpy
, memcpy_s
, operator new
, operator new[]
etc are defined as size_t
, using UINT64
will cause data lose error.
1 | // Defined by Windows SDK |
For more information of fundamental types of C++, refer to msdn.
TODO: C++17 Features
Fold Expressions
1 |
|
EXPRESSION | EXPANSION |
---|---|
(… op pack) | ((pack1 op pack2) op …) op packN |
(init op … op pack) | (((init op pack1) op pack2) op …) op packN |
(pack op …) | pack1 op (… op (packN-1 op packN)) |
(pack op … op init) | pack1 op (… op (packN-1 op (packN op init))) |
Default values of empty parameter packs: &&
: true
; ||
: false
; ,
: void()
.
e.g.
1 | template<typename ...Args> |
tbb Multithread lock
1 | if(multiThreading) |
The lock will be released when it goes out of the bracket.
P4V force sync removed files
1 | p4 diff -sd <path-to-resource>...|p4 -x- sync -f |
Other Tips
- All the tabs in code should be replaced by spaces.
- Must add comments and make them understanded.
- For excetions, we can return
false
,NULL
, etc. However, we should ensure that the whole program would not crash. - Notice some functions, especially related to assert, exceptions, etc. would be skipped under OPTIMIZE compile.
- To debug bugs releated GPU, we must enable GPU Debug Layer. And for many times,
Removing Device
orDevice Hunging
is caused by incorrectly pipeline settings/bindings/etc. - To avoid pow computing, using exponents of a power of 2 (e.g. 2, 4, 8, …), so that it can be implement by shifting.
Mark some useful tools
- Handle
- Performance Monitor
- Code Graph
- Pix
- Process Explorer
- SunLogin
Using .inl
files
https://stackoverflow.com/questions/1208028/significance-of-a-inl-file-in-c
.inl
files are never mandatory and have no special significance to the compiler. It’s just a way of structuring your code that provides a hint to the humans that might read it.
I use .inl files in two cases:
- For definitions of inline functions.
- For definitions of function templates.
In both cases, I put the declarations of the functions in a header file, which is included by other files, then I #include the .inl file at the bottom of the header file.
It separates the interface from the implementation and makes the header file a little easier to read. If you care about the implementation details, you can open the .inl file and read it. If you don’t, you don’t have to.
Signals and Slots
An simple introduction could be found in the blog by simmesimme.
A pattern pre-defined in Qt which makes it easier to implement the Observer pattern. The class based on QObject
can tell the outside world that its state has changed by emitting a signal, valueChanged()
, and it has a slot which other objects can send signals to.
1 |
|
NOTICE: Have no relationship with std::signal
!
Memory Leak
- VS Diagnostic Tool
Analyze CPU and Memory while Debugging
Measure app performance in Visual Studio - CRT Library
Possible reasons:
- Multithread
- Mem Pool
- Temp resource
- Destructor
Include Guards
Preferred: use #pragma once
in header files instead of #ifndef ...
.
Advantages: wiki. For more about pre-processor, refer to this link.