[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Destructor for a packet?



I think your problem belongs to C++ language.
Ns Packet::free() method just frees Packet object.
It does not go to the reference(pointer) and free it , I think.

The first solution, as you know, is to declare mydata as array.
But array has fixed storage so, this seems not a good solution.

The second solution is to insert delete operation explicitly in Packet::free().

I hope this helps you solve the problem.

----------------------------------------------------------------------------
To koreans,
Please visit htttp://mmlab.snu.ac.kr/~hsjeong/ns/index.htm
This is korean web board for ns-2 users.

> I have created a packet header which looks something like this:
> 
> struct hdr_mypkt {
> // ...
> char *mydata;
> // ...
> }
> 
> ...and I dynamically allocate memory (using "new") for "mydata" to point
> to.  (This way I can change the length of a field in the packet.) The
> problem I have is that if I send such a packet through a link, and this
> packet overflows in the queue of the link, [it at least seems that] the
> memory dynamically allocated earlier is not freed.
> 
> Hence I think I need something like a destructor for this packet, which
> will free the memory. But how does one make a destructor, since custom
> packet types are not themselves classes in NS?
> 
> Or, if my approach is incorrect--either 1) in making a variable-length
> packet field, or in 2) freeing the memory of a dynamically-allocated
> field if the packet is dropped by queue overflow--, what should I be
> doing?
> 
> Many thanks for all suggestions!!
> --daniel
> 
> ---------------------------------------------------------------------------
>  Daniel Friedman    [email protected]    http://www.isr.umd.edu/~danielf
> 
>