zoukankan      html  css  js  c++  java
  • 忘记了释放内存,造成内存泄露

    忘记了释放内存,造成内存泄露。

    含有这种错误的函数每被调用一次就丢失一块内存。

    刚开始时系统的内存充足,你 看不到错误。

    终有一次程序突然死掉,系统出现提示:内存耗尽。

    动态内存的申请与释放必须配对,程序中 malloc 与 free 的使用次数一定要相同,否 则肯定有错误(new/delete 同理)。

     1 #include <iostream>
     2 #include <string.h>
     3 
     4 //main()函数
     5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     6 
     7 using namespace std;
     8 int main(int argc, char** argv) {
     9    //声明字符数组
    10     char string[80],*p;
    11     int i;
    12 
    13     //转换字符串中的小写字母为大写
    14     cout<<"Convert a string to uppercase:"<<endl;
    15     cout<<"string:";
    16     cin>>string;
    17     p=strupr(string);
    18     cout<<"p:"<<p<<endl;
    19     cout<<"string:"<<string<<endl;
    20     cout<<"----------------------"<<endl;
    21 
    22     //转换字符串中的大写字母为小写
    23     cout<<"Convert a string to lowercase:"<<endl;
    24     cout<<"string:";
    25     cin>>string;
    26     p=strlwr(string);
    27     cout<<"p:"<<p<<endl;
    28     cout<<"string:"<<string<<endl;
    29     return 0;
    30 }
  • 相关阅读:
    存储结构接收数组
    oracle数据库sql根据查看执行计划优化sql--走不走索引
    多线程--Thread
    java常用集合族谱
    设计模式之二 适配模式
    Tomcat优化问题
    设计模式之一
    C++虚函数表,虚表指针,内存分布
    设计模式
    linux环境下的时间编程
  • 原文地址:https://www.cnblogs.com/borter/p/9413662.html
Copyright © 2011-2022 走看看