Hi Kalle,
KS>> fopen() is not a memory allocation function. It is a file opening
KS>> function. Its compliment is fclose(). You cannot use free() on it.
KS>Oh yes you can. fopen() (in addition to some other, file-related magic)
does
KS>a malloc() for a struct that is used in conjunction with
KS>the other functions of the f*-family to do stream I/O. FILE
KS>is just typedef'd to this struct. When you pass a FILE
KS>pointer to fclose(), it calls free() to the pointer after
KS>doing all other relevant magic (such as flushing the
KS>buffers etc). The return value of fopen() is actually the
KS>return value of the malloc() that fopen() calls to allocate
KS>the space for the FILE struct. Because of this, it can also
KS>be free()d.
This is an invalid generalisation. Not all compilers malloc() the data
structure on each fopen(), some use a pre-allocated array of FILE
structs. In this case free()ing the FILE pointer is not a valid
operation...
KS>No, I'm not saying that you SHOULD free() your file
KS>handles. Just that it CAN be done for the reasons stated
KS>above.
Only for _some_ compilers, certainly not for all.
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)
|