IT 취미생활.  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
2차 배열 동적 할당 - 일반 및 개선
일반 적인 2차 배열 동적 할당


코드:
template <typename Ty>
Ty **alloc2DArray(int width, int height)
{   
 Ty **arr = new Ty*[height];   
 for(int i=0; i<height; i++)   
 {       
  arr[i] = new Ty[width];  
 }   
 return arr;
}
template <typename Ty>
void free2DArray(Ty **&arr, int height)
{  
 for(int i=0; i<height; i++)   
 {       
  delete []arr[i];       
  arr[i] = 0;   
 }  
 delete []arr;   
 arr = 0;
}


고급
int **imatrix( int w, int h ) 
{
 int i;
 int **m;
 m = new int * [h]; 
 if( !m )
  PutError("memory alloc failure in imatrix()"), exit(0);
 m[0] = new int [ w * h ]; 
 if( !m[0] )
  PutError("memory alloc failure in imatrix()"), exit(0);
 for( i = 1; i < h; i++ ) { 
  m[i] = &m[0][ i * w ];
 }
 return m;
}

고급으로 할당 하는 방법에 대해서 눈여겨 보세요.


BLOG main image
취미생활
 Notice
 Category
분류 전체보기 (191)
매일매일갱생 (83)
서버개발 (1)
임베디드개발 (12)
Programming (80)
Personal Projects (6)
유용한 프로그램 (0)
 TAGS
영어 이메일 project 1seg It 군대 알고리즘 M480 벨소리 변경 DVB 티스토리 초대장 DVB-T English Wince5.0 개발자 MP3 warning 티스토리초대 english email 음식 Debug DirectShow spam mail Algorithm Linux VC++ debugging 서태지 Brazil C++ 퇴사 ISDB-T 미라지폰 isdbt Windows Mobile6.0 출장 Java Error Case C Dshow
 Calendar
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
 Recent Entries
 Recent Comments
 Recent Trackbacks
 Archive
 Link Site
zextor
괴짜 프로그래머의 일상사~@@
Gag & Peace, and more..
Kazakhstan Almaty.......
Min-A
Sadgarret
Steve Yoon's log
가슴 뛰는 삶을 살아라
오스틴 파워
GUI sin
melanie parker_Lady
제레미의 TV 2.0 이야기..
 Visitor Statistics
Total :
Today :
Yesterday :
rss