C++对象内存布局

代码一:

itTmp = mapInfo.find("NodeNum");
        if (itTmp != mapInfo.end())
        {
            int nMaxNodes = StrToInt(itTmp->second);
            map<SQLNODED, vector<SQLNODED> > mapNodes;
            CCIM *pCCIM = CCIM::GetInstance();
            pCCIM->GetDataNode(mapNodes);
            printf("There is %d nodes\n", mapNodes.size());
            if (mapNodes.size() > nMaxNodes)
            {
                printf("Too much data nodes, the max data nodes is %d\n", MAX_DATA_NODES);
                return false;
            }
        }

单步调试结果:

代码二:

#include <iostream>
using namespace std;

class CBase
{
public:
    CBase()
    {
        m_nBnum = 10;
    }
    ~CBase()
    {}
private:
    int m_nBnum;
};

class CDerive : public CBase
{
public:
    CDerive()
    {
        m_nDnum = 20;
    }
    ~CDerive()
    {}
private:
    int m_nDnum;
};

int main(int argc, char **argv)
{
    CBase b;
    CDerive d;
    cout << "base size : " << sizeof(b) << endl;
    cout << "derive size : " << sizeof(d) << endl;

    return 0;
}

单步调试结果:

posted @ 2015-03-16 18:41  冷冰若水  阅读(197)  评论(0编辑  收藏  举报