<div>안녕하세요. 프로젝트 하다가 막히는게 있어서 이렇게 질문 드립니다. </div> <div><br /></div> <div>이미지를 나타내는 함수가 있다고 하죠. 하지만 <span style="font-size: 9pt; line-height: 1.5">이미지의 픽셀 사이즈(행 과 열)는 이미지를 넣기 전에 알수 없음으로,</span></div> <div>malloc 함수를 사용하여 변수 float ** m 과 float *v 를 힙 영역에 넣어 두는건 이해하겠습니다.</div> <div>처음에 <span style="font-size: 9pt; line-height: 1.5">m 이 가지는 값은 주소값이 되겠네요 더블포인터 플롯 형 이고요, row * sizeof(float *) 만큼의 바이트를 가지겠네요. (이 것을 그림으로 표현 하였을때 </span><span style="font-size: 9pt; line-height: 1.5">row 개의 박스(일차원 배열로)가 만들어 진다고 가정하고 하나의 row 박스에는 float * 형 주소들이 들어 온다고 하죠 ) </span></div> <div><font color="#00b050"><br /></font></div> <div><font color="#ff0000">그다음 이해가 가지 않는 부분은 </font>왜 변수 float * v 를 정의할때 말록 함수 안에 바이트 크기가 rows * cols * sizeof(float) 인가요?</div> <div>제 생각은 그냥 rows 없이 <span style="font-size: 9pt; line-height: 1.5">cols * sizeof(float)</span><span style="font-size: 9pt; line-height: 1.5"> 이 되어야 할것 같은데요... 그래야 2차원 배열이 만들어 지지 않나요?</span></div> <div><span style="font-size: 9pt; line-height: 1.5"><br /></span></div> <div><font color="#ff0000">다른 또 하나는, </font>v+= cols; 이 부분은 포인터 연산 부분 같은데 *(v+cols) 랑 동일한 문장인가요?</div> <div><font color="#00b050"><br /></font></div> <div><font color="#00b050">/* Allocate memory for a 2D float matrix of size [row,col]. This returns</font></div> <div><font color="#00b050"> a vector of pointers to the rows of the matrix, so that routines</font></div> <div><font color="#00b050"> can operate on this without knowing the dimensions.</font></div> <div><font color="#00b050">*/</font></div> <div>float **AllocMatrix(int rows, int cols)</div> <div>{</div> <div> int i;</div> <div> float **m, *v;</div> <div><br /></div> <div> m = (float **) malloc(rows * sizeof(float *));</div> <div> v = (float *) malloc(rows * cols * sizeof(float)); <font color="#ff0000"><---------</font></div> <div> for (i = 0; i < rows; i++) {</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>m[i] = v;</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>v += cols; <span style="color: #ff0000; font-size: 9pt; line-height: 1.5"><---------</span></div> <div> }</div> <div> return (m);</div> <div>}</div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.