疣猪佩奇丶 2020-08-11 13:43 采纳率: 100%
浏览 145
已采纳

AddXY() 运行久了 内存增加 CPU占用率增加, ((CSeries)m_chart1.Series(nline0)).Delete(0);也用了没用 BoundersCheck 查泄漏也试了 可能是我姿势不对 查不出来,求大佬解答

case 30:
        {       
            /* ———————————————— 显示曲线 ————————————————— */     

            miData = new MIData;                                            //给指针分配一个内存
            if (miData->id > 0)                                             //问题0xC0000005:  是使用了空指针 *ptr = NULL
            {               
                /* —————————————— 开始结束时间 ———————————————— */

                CString bridgeSn, inverterSn;

                CTimeSpan tempSpan_1 = CTimeSpan(0, 0, 1, 35);                  //设置时间间隔
                CTimeSpan tempSpan_2 = CTimeSpan(0, 0, 0, 0);

                CTime t = CTime::GetCurrentTime();                              //获取时间
                CString nowTime = t.Format("%H:%M:%S");

                CTime tStart = t - tempSpan_1;
                CString strTempSt = tStart.Format("%Y-%m-%d %H:%M:%S");         //CTime转CString

                CTime tEnd   = t + tempSpan_2;
                CString strTempEnd = tEnd.Format("%Y-%m-%d %H:%M:%S");      

                /* —————————————— 开始结束时间 ———————————————— */
/*
                COleSafeArray XValue;
                COleSafeArray YValue;


                DWORD pNumElements = (sizeof(fieldName) / sizeof(char *));

                XValue.Create(VT_R8, 1, &pNumElements);
                XValue.Create(VT_R8, 1, &pNumElements);

                long i(0);

                for (i = 0; i < sizeof(fieldName) / sizeof(char *); ++i)
                {

                    XValue.PutElement(&i, pX + i);
                    XValue.PutElement(&i, pX + i);
                }
*/
                if (m_comboBridge1.GetCurSel() != 0)
                    m_comboBridge1.GetWindowText(bridgeSn);
                if (m_comboInverter1.GetCurSel() != 0)
                    m_comboInverter1.GetWindowText(inverterSn);

                if (dataAccess.SearchData(bridgeSn, inverterSn, strTempSt, strTempEnd))
                {
                    /*_CrtDumpMemoryLeaks();*/
                    CRecordset& rs = dataAccess.GetRecordset();
                    CString value;
                    while (!rs.IsEOF())
                    {
                        for (int i = 0; i < sizeof(fieldNamee) / sizeof(char*); ++i)
                        {
                            short index = rs.GetFieldIndexByName(fieldNamee[i]);
                            rs.GetFieldValue(index, value);
                            vec.push_back(value);
                            double douValue = atof(value.GetBuffer());                  //CString 强转成 double

                            switch (i)
                            {
                            case 0:
                                ((CSeries)m_chart1.Series(nline0)).AddXY(s_x, douValue, nowTime, RGB(0, 0, 0));         //AddXY(x, y, x_str, RGB)
                                m++;
                                printf("描点次数为:%d \n", m);
                                break;
                            case 1:
                                ((CSeries)m_chart1.Series(nline1)).AddXY(s_x, douValue, nowTime, RGB(255, 0, 0));
                                break;
                            case 2:
                                ((CSeries)m_chart1.Series(nline2)).AddXY(s_x, douValue, nowTime, RGB(46, 139, 87));
                                break;
                            case 3:
                                ((CSeries)m_chart1.Series(nline3)).AddXY(s_x, douValue, nowTime, RGB(0, 0, 255));
                                break;
                            case 4:
                                ((CSeries)m_chart1.Series(nline4)).AddXY(s_x, douValue, nowTime, RGB(205, 92, 92));
                                break;
                            case 5:
                                ((CSeries)m_chart1.Series(nline5)).AddXY(s_x, douValue, nowTime, RGB(255, 185, 15));
                                break;
                            default:
                                break;
                            }
                            vec.erase(vec.begin() + 0);

                            Sleep(50);
                        }
                        /*m_chart1.UpdateData();*/

                        s_x += 1.0;

                        if (((CSeries)m_chart1.Series(nline0)).get_Count() > 10)
                        {

                            ((CSeries)m_chart1.Series(nline0)).Delete(0);
                            ((CSeries)m_chart1.Series(nline1)).Delete(0);
                            ((CSeries)m_chart1.Series(nline2)).Delete(0);
                            ((CSeries)m_chart1.Series(nline3)).Delete(0);
                            ((CSeries)m_chart1.Series(nline4)).Delete(0);
                            ((CSeries)m_chart1.Series(nline5)).Delete(0);

                            ((CAxis)(((CAxes)m_chart1.get_Axis()).get_Bottom())).Scroll(1.0, TRUE);

                        }
                        rs.MoveNext();

                        Sleep(100);     

                    }

                }

            }
            delete miData;

        }
        break;
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-08-11 22:30
    关注

    你到底有多少数据,什么进程占用的cpu高,是不是数据库那一块,或者你的数据天然地太多了。关闭窗口,内存下降么。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?