与えられた一連のポイント (ランダムに生成) 内のすべてのポイントの k 最近傍点を見つけるための C プログラムを作成しました。問題は、ポイントの数 (および結果として配列サイズ) を 10000 に増やすと、関数を呼び出して最近傍を見つけるとすぐにプログラムがセグメント違反エラーを出すことです。デバッガーを使用して関数内に入ることができません。「ステップ イン」を実行するとすぐに、プログラムがクラッシュします。
コードブロックと Eclipse CDT (Windows 7) を使用しましたが、両方とも同じ時点でエラーが発生します。コードブロックの場合はセグメント違反が発生し、Eclipse の場合は最初に「0x4039a7 で __chkstk_ms() のソースが利用できません」と表示され、次に OS 自体からエラーが発生します -「KNN.exe は動作を停止しました」ただし、プログラムは Linux (Ubuntu 32bit) で問題なく動作します。
コード スニペットは次のとおりです。
#定義 MAX_SIZE 10000
int main()
{
int n = MAX_SIZE;
int k = 3;
int i;
double points[MAX_SIZE*2]; //2-D array in row-major order
double result[MAX_SIZE*3*2];
srand(time(NULL));
for(i=0; i < n; i++)
{
points[i*2] = (double)rand()/(double)RAND_MAX;
points[i*2 + 1] = (double)rand()/(double)RAND_MAX;
}
seek(points,n,k,result); //<---------- ERROR
seek(points,n,k,result); //<------------ NO ERROR
....
}
void seek(const double * const points, int n, int k, double *result)
{
TreeNode qtree[MAX_SIZE];
int order_array[MAX_SIZE];
int num_nodes = build_quadtree(a, n, k, qtree,order_array);
......
}
struct tree_node { int id; int num_points; int start_order; int end_order; int 親; int 子 [4]; 構造体の四角形 rect; enum boolean is_leaf; };
構造体ポイント{ダブルx; ダブルy; };
構造体の四角形 { int id; ダブル xmin、xmax、ymin、ymax; 構造体ポイント midpt; };
What is more confusing is that I have another function with the same arguments which is running without any problem. Please provide suggestions on how to debug this.
EDIT:- . I have posted the first few lines of seek() function. As the replies have pointed out I am actually allocating a lot of memory on the seek function but I am wondering why it is not a problem in linux.