Malloc/Free Patch

Adam Charrett ajmcharrett at hotmail.com
Tue Feb 13 16:32:32 CET 2007


Yes, I think your suggestion are the best way forward, and it was something I had thought about but not looked into.I hate to say it but my patch was a 'hack' to try and reduce the memory fragmentation I was seeing.CheersAdam> Date: Mon, 12 Feb 2007 13:33:29 +0100> From: massiot at via.ecp.fr> To: libdvbpsi-devel at videolan.org> Subject: Re: Malloc/Free Patch> > Hello,> > On Sun, Feb 11, 2007, Adam Charrett wrote:> > I would just like to say that I have been using libdvbpsi for the last year and think its great, the only library that fulfilled my needs and works!I've been using libdvbpsi in my application, dvbstreamer, and have been finding that there was a huge number of malloc/frees which seemed to be causing some memory fragmentation, so I modified libdvbpsi to only allocate more memory if it didn't already have a free section to use.I've include the patch here, I hope you consider it helpful. On average it reduce the malloc/free count from several million (when running continuously for a day or 2) to 2.ThanksAdam Charrett> > I am grateful for the idea. However your patch has two critical issues> which make it impossible to merge it into the SVN trunk :> > > + * List of sections available for reuse.> > + ****************************************************************************/> > +static dvbpsi_psi_section_t * sp_free_sections = NULL;> > 1. We can't use a static variable in libdvbpsi because it must be> reentrant. If two threads call the libdvbpsi patched with your code, it> is likely to lead to a major heap corruption within a few seconds. A> solution would be to use mutexes but this would bring latency and> portability issues, so I think the best is to keep one cache per> libdvbpsi instances, and put the chained list in the dvbpsi_decoder> structure.> > > +void dvbpsi_FreePSISectionsCache(void)> > +{> > +   dvbpsi_DeletePSISections(sp_free_sections);> > +   sp_free_sections = NULL;> > +}> > 2. Also we want to keep source-level API compatibility as far as> possible. With this change you must modify all applications using> libdvbpsi to call dvbpsi_FreePSISectionsCache() when exiting, otherwise> creating a memory leak. dvbpsi_FreePSISectionsCache should get called> automatically when the dvbpsi handle is released.> > -- > Christophe Massiot.> > -- > This is the libdvbpsi-devel mailing-list, see http://developers.videolan.org/> To unsubscribe, go to: http://developers.videolan.org/lists.html> 
_________________________________________________________________
Personalize your Live.com homepage with the news, weather, and photos you care about.
http://www.live.com/getstarted.aspx?icid=T001MSN30A0701
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.videolan.org/pipermail/libdvbpsi-devel/attachments/20070213/66f46bc8/attachment.htm 


More information about the libdvbpsi-devel mailing list