将地图替换为矢量

时间:2014-09-30 10:51:01

标签: c++ vector stdmap

我将地图替换为矢量<对< long,Object> >因为记忆。我需要休息一些内存(甚至几Mb),我读到地图需要更多的虚拟内存。所以我遇到了一个问题:

bool CClass::generateMap(int num,  const long*& fg,
                                      CObjekt *pObjekt) const
{
    foId_t tmpFo = fg[OBJECT_IDX];
    CAttribute *pAttribute;
    objectMap_it tmp_it = pObjekt->objectMap.find(tmpFo);
    if(tmp_it != (pObject->objectMap.end()))
    {
        pAttribute = (*tmp_it).second;
    }
    else
    {
        pAttribute = new COlageAttribute();
        pObject->objectMap[tmpFo] = pAttribute; 
    }
    if((generateAttributeMap(fg, pAttribute) == false))
    {
        return false;
    }
    return true;
}

因此。现在我想将objectMap地图替换为对的Vector。但我有问题:我想用循环但第一次我的Vector返回大小0,这是不能正常工作。我认为我做错了,所以我把我的示例代码放在这里:

for(int i=0; i<pObject->objectVector.size(); i++)
{
    test = pObject->objectVector[i].first;
    if(test==tmpFo)
    {
        pAttribute = pObject->objectVector[i].second;
    }


    else
    {

        pAttribute = new CAttribute();
        pObject->objectVector[it].second = pAttribute;
    }

}

0 个答案:

没有答案
相关问题