Hi John,
You asked:
JD>BB Free() is just the counterpart of malloc().
JD>I know what free does but how does it do it.
You don't need to know in detail! I don't, I could work it out by
looking at the library source but I haven't found any need to bother in
all my years of programming.
JD>It has the starting address of the passed variable &variable[0].
JD>How does it know where it ends ???
Each time you allocate memory with malloc() it sets up a control block
which includes information about the size of the block allocated (which
may not be the size you requested but rounded up to processor dependant
boundaries to optimise operation). The information in the control block
is used by free() and the other heap management routines.
JD>It just doesn't free up to the first '\0', it frees it all.
It can't, the mallcoed memory may contain only zeros :-)
George
* SLMR 2.1a * Wastebasket: Something to throw things near.
--- Maximus/2 3.01
---------------
* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)
|