ページ 11

C言語 ポインタ 解放

Posted: 2011年12月08日(木) 03:57
by texture_man
C言語のポインタの解放について質問が御座います。
現在Windows系 VisualC++という環境でプログラミングしておりますが。
下記のコードでポインタがうまく解放出来ているかどうかです。
私は

コード:

for(int i=0; i<vectors; i++) free(h[i]);
という行が最終行の前に必要と考えていますが、意見お願いします。

コード:

uchar ***h = (uchar***)malloc(sizeof(uchar**)*vectors);
for(int i=0; i<vectors; i++) h[i] = (uchar**)malloc(sizeof(uchar*)*256);
for(int i=0;i<vectors;i++){
	for(int j=0;j<256;j++){		
		h[i][j] = (uchar*)malloc(sizeof(uchar)*256);
	}
}

for(int i=0; i<vectors; i++){
	for(int j=0;j<256;j++){
		free(h[i][j]);
	}
}

free(h);

Re: C言語 ポインタ 解放

Posted: 2011年12月08日(木) 07:26
by beatle
僕も必要だと思います。

Re: C言語 ポインタ 解放

Posted: 2011年12月11日(日) 15:14
by texture_man
返信ありがとうございます。周りにわかる方がいなくて困っていたのですが、意見が合ったの解決とします。