[ECOS] fopen/fclose

Jurica Baricevic jura@INTESIS.hr
Mon Mar 25 08:46:00 GMT 2002


Andrew Lunn wrote (Monday, March 25, 2002 09:33):
> On Fri, Mar 22, 2002 at 05:01:07PM +0100, Jurica Baricevic wrote:
> > Hi!
> >
> > I have a quite simple question regarding memory
> allocation/deallocation in
> > fopen/fclose :-)
> >
> > It seems that fopen() creates stream with new operator (fopen.cxx:133):
> >    stream = new Cyg_StdioStream(....);
> >
> > while its pair fclose() destroys it with the following combination
> > (fclose.cxx:101):
> >    stream->~Cyg_StdioStream();
> >    free(stream);
> >
> > I wonder what could be the reason for not using delete operator
> in fclose()
> > instead?
>
> Have a look at infra/current/src/delete.cxx.
> CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS is enabled by default since most
> eCos programs don't do dynamic stuff with memory. They create what
> they need at startup and keep it forever. Hence the delete operator is
> not needed.
>
> FILE operations are the exception to this.
>

Thank you very much Andrew. This clarifies the non-conventional pair
new/free.
However, I don't understand why FILE operations wouldn't use delete when
CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS is disabled (... #ifdef
CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS ... #else...#endif ...)?
Specifically, I need to overload default new/delete operators and this might
not be possible if 'fopen()' uses new, while 'fclose()' does not call
delete.


Best regards and thanks,
Jura



-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss



More information about the Ecos-discuss mailing list