2011年11月2日水曜日

Using large arrays in C

If you declare large arrays in functions, you might encounter "segmentation fault" error in runtime.

You can avoid this problem by
1) changing the limit of stack size
2) making the large arrays global variables
3) use malloc


関数内で配列を宣言 ⇒ スタック領域を使用

スタックが足りなくなると、動作時に segmentation fault エラー

解決法:
1) スタック領域制限の変更
bash: ulimit -s
qsub: スクリプト中に以下の一文を入れる (うまく動いていない? 要調査)
#$ -l h_stack=256M

2) 巨大配列はグローバル変数とする

3) malloc で動的確保

0 件のコメント:

コメントを投稿