Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 23 Sep 2011 17:19:09 -0500 Message-ID: <4E7D05DE.4960@mindspring.com> Date: Fri, 23 Sep 2011 18:19:10 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: evaluate a generic swap function References: <11027611.3262.1316798819548.JavaMail.geo-discussion-forums@yqjc18> <0.cd4cbe9b01c698079f35.20110923183607BST.87y5xfw48o.fsf@bsb.me.uk> <2208063.1130.1316800191576.JavaMail.geo-discussion-forums@yqih9> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 16 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.218.20 X-Trace: sv3-2VP2ezg4OgGFropXqvZ6SDSZfraU6iMUjC+/nvat2vHKSgeGgaqe9yPjprRi1abNMsNmOCyfWJ3YSL0!/XKs5kAf5cBLe9PzoVO8MVqnINpEz/rGLL5FyYyjiclCpc2LZzYN7y5aX7kocgb/UsgC2WZEARmM!t5pYdkylMQ== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2158 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:10825 Nelu wrote: > Yes, but memory for the tmp variable in your example is allocated/deallocated every time you enter/exit the block of code. The static variable is allocated at the start of the program and successive calls to the function will not need to allocate more memory. Same with the thread local variables as long as you reuse the same threads, no? If you want instead, to have a single memory reservation for multiple function calls, and also to have thread safety, then you could copy the technique used for the renentrant varieties of strtok, commonly available on many systems and usually known as either strtok_r or strtokr. You add another parameter to the swap function with the address of the scratch memory. The scratch memory is reserved in the calling function and can have any kind of duration. -- pete