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
C 음식 M480 VC++ DVB 퇴사 spam mail MP3 Error Case 개발자 Brazil project 영어 이메일 티스토리 초대장 알고리즘 Dshow Java warning DVB-T Linux Algorithm C++ English 1seg debugging ISDB-T 군대 It 미라지폰 출장 isdbt DirectShow Windows Mobile6.0 Wince5.0 Debug english email 벨소리 변경 티스토리초대 서태지
 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