zoukankan      html  css  js  c++  java
  • 几个崩溃问题

    一直喜欢在类里组织数据时候用map。。

    最近有个进程经常性崩溃。。。仔细查阅代码。。怎么着也看不出原因来。

    后来发现 坑竟然是:

    map [] 如果key不存在。则会在执行玩操作之后给对应map塞一个默认值进去。

    测试代码如下:

     1 map<string, int> mx;
     2 const int testMxRet(const string& s)
     3 {
     4     return mx[s];
     5 }
     6 
     7 void testMxx()
     8 {
     9     m[1] = "111";
    10     m[2] = "222";
    11     m[3] = "333";
    12 
    13     cout << testMapRet(1) << endl;
    14 
    15     auto sRet2 = testMapRet(2);
    16     cout << sRet2 << endl;
    17 
    18     auto sRet4 = testMapRet(4);
    19     cout << sRet4 << endl;
    20 
    21     if (sRet4 != "")
    22     {
    23         cout << "ret4!=''" << endl;
    24     }
    25     else
    26     {
    27         cout << "ret4==''" << endl;
    28     }
    29 
    30     mx["111"] = 1;
    31     mx["222"] = 2;
    32     mx["333"] = 3;
    33 
    34     auto iRet1 = testMxRet("111");
    35     auto iRet2 = testMxRet("222");
    36     auto iRet4 = testMxRet("444");
    37 
    38     cout << iRet1 << "|" << iRet2 << "|" << iRet4 << endl;
    39 
    40     cout << endl;
    41     for (auto it : mx)
    42     {
    43         cout << it.first << "|" << it.second << endl;
    44     }
    45 }

    最后执行下来的结果:

    mx里面有4个元素。。"444"为key的也是其中一个元素。。真是坑爹。。

    函数执行时候调用一次就生成一个数据插入到map中。当函数的被调用量一大,就突然之间崩溃了。。





    另一个坑爹的崩溃:
    某次进程一启动就崩溃。看了好几个coredump都崩的不知所以。。
    后面一查 原来linux的shm用完了。。查了半天。记录一下
  • 相关阅读:
    【七款炫酷的页面特效】
    【PHP环境-WampServer踩坑】
    【Elasticsearch在winodws系统启动报could not find java+闪退】
    【Vue-入门笔记-7】
    关于ios的光标和键盘回弹问题
    AES加密然后ajax传输数据
    文件进行MD5计算
    jqGrid 常用 总结 -2
    关于页面传参,decodeURI和decodeURIComponent
    js防抖和节流
  • 原文地址:https://www.cnblogs.com/yylingyao/p/8295310.html
Copyright © 2011-2022 走看看