Article View: comp.lang.c.moderated
Article #2553Re: void* type
From: James
Date: Mon, 08 Apr 1996 16:20
Date: Mon, 08 Apr 1996 16:20
32 lines
1816 bytes
1816 bytes
In article <4jmcnr$lr2@solutions.solon.com> stanr@tiac.net (Stan Ryckman) writes:
> int
> swap( void* a , void* b , size_t sz )
> {
> unsigned char buffer[ EXPECTEDMAXSIZE ] ;
> void* tmp = (sz <= sizeof( buffer ))
> ? buffer
> : malloc( sz ) ;
Or, if you don't need reentrant or resursive code, you can do:
static void *tmp = NULL;
static size_t tmp_sz = 0;
if (sz > tmp_sz) {
.... use realloc here .... you get the idea ....
Isn't this a bad thing to do though ?
Because as I see it you only have to have one call to the function
with sz being large and then you have that mem eaten up forever even
if all your other calls will always be small. Also seeming that you
are using realloc anyway... wouldn't it be better to have the tmp
pointer as a static global and then you can have another function
which is called on shuting down, that will free your mem.
~J
--
/* James Antill **WWW** http://cswww2.essex.ac.uk/users/loser/ */
#include <stdio.h>
main(int c, char **v){char *a="";if(c==2)while((c=getchar())!=EOF){if(!
*a)a=v[1];c^=*a++;putchar(c);}else printf(" %s <key>\n",v[0]);exit(0);}
Technical Details
Message-ID:
<4kbec8$ejh@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4iepre$ag7@solutions.solon.com> <4ja3qf$p9b@solutions.solon.com> <4jckqc$a5o@solutions.solon.com> <4jibl5$89u@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: James <jmanti@essex.ac.uk> Newsgroups: comp.lang.c.moderated Subject: Re: void* type Date: 8 Apr 1996 11:20:24 -0500 Organization: Essex University, England Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4kbec8$ejh@solutions.solon.com> References: <4iepre$ag7@solutions.solon.com> <4ja3qf$p9b@solutions.solon.com> <4jckqc$a5o@solutions.solon.com> <4jibl5$89u@solutions.solon.com> Reply-To: James <jmanti@essex.ac.uk> NNTP-Posting-Host: solutions.solon.com