進哥的布拉格

Chin Gooole's Blog

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

三維指標-記憶配置與刪除(.net2005編譯)

#include <stdio.h>
#include 
"stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
   
int length = 4, width = 5, depth = 6;
   
char *** video;

   video 
= new char**[length];

   
// allocate the memory storage
   for(int i=0; i<length; i++)
   {
       video[i] 
= new char*[width];
       
for(int j=0; j<width; j++)
           video[i][j] 
= new char[depth];
   }

   
// not needed, just set values to video[][][]
   for(int i=0; i<length; i++)
       
for(int j=0; j<width; j++)
           
for(int h=0; h<depth; h++)
               video[i][j][h] 
= i+j+h;

   
// delete the memory storage
   for(int i=0; i<length; i++)
   {
       
for(int j=0; j<width; j++)
           delete [] video[i][j];

       delete [] video[i];
   }

   delete [] video;

   
// set the pointer ***video to "NULL"
   video = NULL;
   
return 0;
}

 

posted on 2008-10-13 22:35  進哥  阅读(113)  评论(0编辑  收藏  举报