CnUnix

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ CnUnix ] in KIDS
글 쓴 이(By): ahsarang (.아.사.랑.)
날 짜 (Date): 2002년 7월  4일 목요일 오후 11시 37분 46초
제 목(Title): Re: gcc compile setting에서...




  gcc stack size늘리는건 몰겠고요.
  글구 재귀함수라면 이건 좋은 solution이 아닐겁니다.
  아래 코드를 사용해보세요.

@ recursive function아라서 전역변수 혹은 static 변수는 사용할 수 없는 경우맞죠?

------------- 여기부터 --------------
int **
my_alloc(void)
{
    int **p;
    int i;

    p = (int **)malloc(sizeof(int *) * 1000);
    for (i=0; i<1000; i++) {
        p[i] = (int *)malloc(sizeof(int) * 1000);
    }

    return p;
}

void
my_free(int **p)
{
    int i;
    for (i=0; i<1000; i++) {
        free(p[i]);
    }
    free(p);
}


/* 현재 이렇다면... */
your_recursive_function()
{
int a[1000][1000];
if (a_condition)
your_recursive_fucntion();
return;
}

/* 이렇게 바꿔주세요. */
your_recursive_function()
{
int **a = my_malloc();
if (a_condition)
your_recursive_fucntion();
my_free(a);
return;
}
/*
  NO WARRANTY :)

  변수 a는 배열로 선언했을때랑 똑같이 a[10][9] 요런식으로 사용하면 됩니다.
  return your_recursive_function(); 요렇게 사용하지 않도록 주의하세요.
  메모리 줄줄 셉니다.
*/
----------- 여기까지 -----------------






[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.