#pragma intrinsic (_InterlockedIncrement) #pragma intrinsic (_InterlockedDecrement) #pragma intrinsic (memcpy)
The intrinsic pragma tells the compiler that a function has known behavior. The compiler may call the function and not replace the function call with inline instructions, if it will result in better performance. Link
For Windows
__declspec(align(8)) volatile long m_lRefCount;
For Linux
__attribute__((aligned(8))) volatile long m_lRefCount;
This usage make the align for variable and require the value from variable, not from register.
保证申请的代码是在这个类对象之后,+1相当于+sizeof(class),因为指针的+-是根据左操作数来决定的。
inline unsigned char *GetBuffer() { // the buffer follows immediately after this class return (unsigned char *)(this + 1); };