Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[問題] 請問 memory release 的問題

0 views
Skip to first unread message

��

unread,
Dec 24, 2009, 10:19:05 PM12/24/09
to
�аݤ@�Ӳ°��D...

���]�ڦ��@��struct

typedef struct {
int iID;
int* aiList;
}STRUCT_A;

void main()
{
STRUCT_A tA;

//initial struct tA
tA.iID = 100;
ta.aiList = (int*)calloc(5, sizeof(int));

//.....

//reset struct tA
memset(&tA, 0, sizeof(structA;));

==>�g�L�o�ӫ�Astruct ��element ���|�Q�]�� 0
�]�A�ʺA array : aiList
�ڪ����D�O:
(1) �g�Lmemset ��A�o�� aiList �� memory ���Q release �ܡH
���`�� release �|�g��
if (aiList) free(aiList);
aiList = NULL;
�g�Lmemset ��0��A����O�֤Ffree���ʧ@�A�������г]��0
���쥻 aiList ��memory �O���O�|�@���Q��?��{�������H
�]�N�O���A����O aiList �� address �Q�]��0�A�� aiList �� element
���M�٦b�H


(2) �p�G�ڭn���ҤW���o��ơA�аݭn��򰵡H
�ڸչL��� aiList �� address �O�U��...���L�n�����O�o���� ...XD
}

���¦U�� :)

--

--
�� �o�H��: �����~�{(ptt.cc)
�� From: 60.251.142.155

0 new messages