作者: admin

  • Profiling C++ performance in windows

    Profiling in software

    http://en.wikipedia.org/wiki/Software_profiling

    In software engineering, performance analysis, more commonly known today as profiling, is the investigation of a program’s behavior using information gathered as the program executes (i.e. it is a form of dynamic program analysis, as opposed to static code analysis). The usual goal of performance analysis is to determine which sections of a program to optimize — usually either to increase its speed or decrease its memory requirement (or sometimes both).

    continue to read online:

    http://docs.google.com/View?id=dcrhkvwg_124f7b38qfm

  • Useful code snippet : GetBit & SetBit functions

    If you want to manipulate the bit in BYTE array, following functions are useful to you.

    BYTE GetBit(BYTE* pBuffer, int nBit)
    {
        int bitOffset = nBit & 7;
        BYTE ret = pBuffer[nBit >> 3] >> bitOffset;
        ret &= 1;
        return ret;
    }

    void SetBit(BYTE* pBuffer, int nBit)   
    {
        BYTE val = 1 << (nBit & 7);
        pBuffer[nBit >> 3] |= val;
    }

    For the GetBit, nBit is the bit offset you want to test.

    nBit & 7 is equal to nBit % 8, it will get bit offset for input parameter nBit.

    nBit >> 3 is equal to nBit / 8, it will get the byte offset in Byte array.

    Why we use bit operations instead of mod and div operation? The reason is simple, for the bit operation, it will generate more fast and simple assembly code. You could see my build result like:

    ; 160  :     unsigned int modVal = i % 8;

        mov    eax, DWORD PTR _i$[ebp]
        xor    edx, edx
        mov    ecx, 8
        div    ecx
        mov    DWORD PTR _modVal$[ebp], edx

    ; 161  :
    ; 162  :     unsigned int andVal = i & 7;

        mov    eax, DWORD PTR _i$[ebp]
        and    eax, 7
        mov    DWORD PTR _andVal$[ebp], eax

    The code is generated by VC2008 and disabled optimization. For mod operation "i % 8", it has "div" and will be slow then "i & 7".

  • 笔记:C (C++)语言中数组与指针的区别

    -关于《c专家编程》的读书笔记

    —————————————————

    试验目的1,比较指针与数组取值方式的异同。2,比较指针与数组作为函数参数时候的异同。

    (更多…)

  • 笔记:c语言中的复杂声明

    最近在复习c(c++)语言里面的复杂声明,这个东西真是麻烦的紧啊。

    (更多…)

  • 时光

    看时光飞逝,我回首从前。。。

    IMG_1217

    IMG_1756

    IMG_5629

    IMG_6131

    IMG_6500

    IMG_6685

    Picture 055

    IMG_7292

    IMG_7007