CnUnix

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ CnUnix ] in KIDS
글 쓴 이(By): ksangeun (우주인)
날 짜 (Date): 2003년 6월 17일 화요일 오전 09시 05분 49초
제 목(Title): Re: struct 내에 동적메모리 할당


의도하신 바를 모르겠어서 맞았는지 틀렸는지 모르겠는데요..

아래와 같은 사용방법이 의도하신 바가 아닌가 싶습니다..

main(void)
{
testd* pTestSrc;
testd* pTestDest;
pTestSrc = AllocTest();
pTestDest = AllocTest();

/*use above pointer anyway you want here...*/

CopyTest(pTestDest, pTestSrc);
FreeTest(pTestSrc);

/*do something that you want to do */

FreeTest(pTestDest);

}

testd* AllocTest()
{
testd* p;
p = (testd*)malloc(sizeof(testd));
p->arra = (int*)malloc(sizeof(int)*4000);
p->arrb = (int*)malloc(sizeof(int)*4000);
return p;
}

void FreeTest(testd* p)
{
free(p->arra);
free(p->arrb);
free(p);
}


void CopyTest(testd* dest, testd* src)
{
memcpy(dest, src, sizeof(testd));
memcpy(dest->arra, src->arra, sizeof(int)*4000);
memcpy(dest->arrb, src->arrb, sizeof(int)*4000);
}




p.s. 제 질문에도 답을 을 좀....

     만화좀 보게 해 주세요.~~


=======================================================================
main(){int a=107,j=2;while(a>-5000){a=a>0?a:99;putchar(a);
a=j==49?46:a-j;j*=j;j=j%256?j:7;j*=j%16?1:-1;};printf("%cm\n",111);};
=======================================================================

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