Hi,
I am a rather new C++/ROOT programmer and I am confused about the operator
delete and the member function Delete(). Here is a code section that I
want to use as an example:
while(1){
TMessage *dmess;
// daqsock is a TSocket*, created earlier
// len is an Int_t, declared earlier
// mtype is a Unt_t, declared earlier
len=daqsock->Recv(dmess);
mtype = dmess->What();
//
// other code here
//
// now done with dmess
dmess->Delete();
// kMESS_RAWI32 is a message type that I defined
if( mtype == kMESS_RAWI32)
continue;
else
break;
}
My confusion arises over the fact that this loop will only execute
once. The second time through it causes a seg fault when I do
len=daqsock->Recv(dmess);. What exactly did Delete do here?
The solution to this problem is to substitute:
delete dmess; <-> dmess->Delete();
Everything seems to work ok in this case, but I don't really know why! I
think that I understand the role of delete in removing objects from the
heap, but, then what does Delete() do? Does Delete() remove objects from
the stack(!)? My question is, when do I use Delete()? What, precisely,
does Delete() do?
Thanks!
Mike Kordosky
--
Graduate Research Assistant // High Energy Physics Lab
kordosky@hep.utexas.edu // University of Texas at Austin
ph: (512) 471-3526
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:35 MET