首页 > 编程语言 > 详细

C++对象内存布局

时间:2015-03-16 19:03:47      阅读:335      评论:0      收藏:0      [点我收藏+]

代码一:

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;
}

单步调试结果:

技术分享

C++对象内存布局

原文:http://www.cnblogs.com/lit10050528/p/4342521.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!