<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body><div style="text-align: left;">Yes, I think your suggestion are the best way forward, and it was something I had thought about but not looked into.<br>I hate to say it but my patch was a 'hack' to try and reduce the memory fragmentation I was seeing.<br><br>Cheers<br><br>Adam<br></div><br><br><br><hr id="stopSpelling">> Date: Mon, 12 Feb 2007 13:33:29 +0100<br>> From: massiot@via.ecp.fr<br>> To: libdvbpsi-devel@videolan.org<br>> Subject: Re: Malloc/Free Patch<br>> <br>> Hello,<br>> <br>> On Sun, Feb 11, 2007, Adam Charrett wrote:<br>> > 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<br>> <br>> I am grateful for the idea. However your patch has two critical issues<br>> which make it impossible to merge it into the SVN trunk :<br>> <br>> > + * List of sections available for reuse.<br>> > + ****************************************************************************/<br>> > +static dvbpsi_psi_section_t * sp_free_sections = NULL;<br>> <br>> 1. We can't use a static variable in libdvbpsi because it must be<br>> reentrant. If two threads call the libdvbpsi patched with your code, it<br>> is likely to lead to a major heap corruption within a few seconds. A<br>> solution would be to use mutexes but this would bring latency and<br>> portability issues, so I think the best is to keep one cache per<br>> libdvbpsi instances, and put the chained list in the dvbpsi_decoder<br>> structure.<br>> <br>> > +void dvbpsi_FreePSISectionsCache(void)<br>> > +{<br>> > + dvbpsi_DeletePSISections(sp_free_sections);<br>> > + sp_free_sections = NULL;<br>> > +}<br>> <br>> 2. Also we want to keep source-level API compatibility as far as<br>> possible. With this change you must modify all applications using<br>> libdvbpsi to call dvbpsi_FreePSISectionsCache() when exiting, otherwise<br>> creating a memory leak. dvbpsi_FreePSISectionsCache should get called<br>> automatically when the dvbpsi handle is released.<br>> <br>> -- <br>> Christophe Massiot.<br>> <br>> -- <br>> This is the libdvbpsi-devel mailing-list, see http://developers.videolan.org/<br>> To unsubscribe, go to: http://developers.videolan.org/lists.html<br>> <br><br /><hr />Personalize your Live.com homepage with the news, weather, and photos you care about. <a href='http://www.live.com/getstarted.aspx?icid=T001MSN30A0701' target='_new'>Try it!</a></body>
</html>