Article View: comp.lang.misc
Article #1891Re: REFs or aliases? (was Re: C's sins of commission)
From: Barry Margolin
Date: Fri, 02 Nov 1990 00:28
Date: Fri, 02 Nov 1990 00:28
38 lines
1472 bytes
1472 bytes
Here's an example of code that uses pointers in a way that I don't think
arrays can substitute. Something like this appeared in code that a friend
wrote several years ago:
foo() {
char auto_buffer[BUFSIZ];
char* bufp;
int in_size;
if ((in_size = input_size()) < BUFSIZ)
bufp = auto_buffer;
else
bufp = malloc (in_size);
get_input (bufp);
...
if (bufp != auto_buffer)
free (bufp);
}
The code was written this way because it is generally more efficient to use
stack-allocated data than heap data, but it can be difficult or inefficient
to make stack-allocated buffers big enough for all uses (some systems have
limits on stack frame size). BUFSIZ is set big enough for most of the
common cases, but in extreme cases the code goes to the heap.
Most of the alternatives to pointers can't deal will with situations where
the reference can either by an automatic or heap object, decided at
runtime.
--
Barry Margolin, Thinking Machines Corp.
barmar@think.com
{uunet,harvard}!think!barmar
Technical Details
Message-ID:
<1990Nov2.002843.28959@Think.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!think.com!barmarReferences:
<8960021@hpfcso.HP.COM> <4667@lanl.gov>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.misc Subject: Re: REFs or aliases? (was Re: C's sins of commission) Message-ID: <1990Nov2.002843.28959@Think.COM> Date: 2 Nov 90 00:28:43 GMT References: <8960021@hpfcso.HP.COM> <4667@lanl.gov> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 38