Navigation

    CFD中文网

    CFD中文网

    • Login
    • Search
    • 最新

    List类的clear()函数

    OpenFOAM
    2
    4
    575
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V
      Vortex last edited by

      最近编程要用到List类。看了下其中的clear()函数发现其只是让成员size变成0,成员指针指向的内存似乎没有清除啊?!这样不会很危险吗?
      clear()函数的注释是这样的
      //- Clear the addressed list, i.e. set the size to zero.
      // Allocated size does not change
      这里的Allocated size和size的区别是什么?
      求大佬们赐教一波~

      1 Reply Last reply Reply Quote
      • 刘
        刘雄国 last edited by

        可以参照vector<>内存管理模式,网上很多资料。不清空内存是为了防止堆空间内存反复allocate和delete,防止重复调用系统资源,这样运行速度下降。allocated size是分配了多少空间,size是你用多少个空间。
        double a[10] = {1,1,1};
        类似这种,分配10个double空间,实际上只用了3个double空间,当然这使用的是栈内存。

        V 1 Reply Last reply Reply Quote
        • V
          Vortex last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote
          • V
            Vortex @刘雄国 last edited by

            @刘雄国 赞,太感谢了。我赶紧去补一下vector<>:146:

            1 Reply Last reply Reply Quote
            • First post
              Last post

            CFD中文网 | 东岳流体 | 京ICP备15017992号-2