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
", mapNodes.size());
            if (mapNodes.size() > nMaxNodes)
            {
                printf("Too much data nodes, the max data nodes is %d
", 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;
}

单步调试结果:

原文地址:https://www.cnblogs.com/lit10050528/p/4342521.html