The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] Did realloc ever zero the new memory?
@ 2015-09-13  0:32 Doug McIlroy
  2015-09-13  1:15 ` Larry McVoy
  2015-09-13  1:30 ` Random832
  0 siblings, 2 replies; 26+ messages in thread
From: Doug McIlroy @ 2015-09-13  0:32 UTC (permalink / raw)


> Did any Unix or Unix like OS ever zero fill on realloc?

> On zero fill, I doubt many did that.  Many really early on when memory
> was small.

This sparks rminiscence. When I wrote an allocation strategy somewhat
more sophisticated than the original alloc(), I introduced realloc() and
changed the error return from -1 to the honest pointer value 0. The
latter change compelled a new name; "malloc" has been with us ever since.

To keep the per-byte cost of allocation low, malloc stuck with alloc's
nonzeroing policy. The minimal extra code to handle calls that triggered
sbrk had the startling property that five passes through the arena might
be required in some cases--not exactly scalable to giant virtual address
spaces!

It's odd that the later introduction of calloc() as a zeroing malloc()
has never been complemented by a similar variant of realloc().

> Am I the only one that remembers realloc() being buggy on some systems?

I've never met a particular realloc() bug, but realloc does inherit the
portability bug that Posix baked into malloc(). Rob Pike and I
requested that malloc(0) be required to return a pointer distinct from
any live pointer. Posix instead allowed an undefined choice between
that behavior and an error return, confounding it with the out-of-memory
indication. Maybe it's time to right the wrong and retire "malloc".
The name "alloc" might be recycled for it. It could also clear memory
and obsolete calloc().

Doug



^ permalink raw reply	[flat|nested] 26+ messages in thread
[parent not found: <1441931343.25526.for-standards-violators@oclsc.org>]
* [TUHS] Did realloc ever zero the new memory?
@ 2015-09-11 15:41 Norman Wilson
  2015-09-11 16:44 ` scj
  0 siblings, 1 reply; 26+ messages in thread
From: Norman Wilson @ 2015-09-11 15:41 UTC (permalink / raw)


I've used realloc a lot, and never run into bugs.  Maybe I've just
been lucky, or maybe it's that I probably didn't use it that much
until the latter 1980s, and then more with pukka Doug malloc code
than with the stuff floating around elsewhere.

Never mind that sometime around 1995 I found a subtle bug in the
pukka Doug malloc (not realloc): arena blew up badly when presented
with a certain pattern of alternating small and large allocs and frees,
produced by a pukka Brian awk regression test.  I had a lot of (genuine)
fun tracking that down, writing some low-level tools to extract the
malloc and free calls and sizes and then a simulator in (what else?)
awk to test different fixes.  Oh, for the days when UNIX was that
simple.

I've never heard before of a belief that the new memory belonging
to realloc is always cleared, except in conjunction with the utterly-
mistaken belief that that's true of malloc as well.  I don't think it
was ever promised to be true, though it was probably true by accident
just often enough (just as often as with malloc) to fool the careless.

Norman Wilson
Toronto ON



^ permalink raw reply	[flat|nested] 26+ messages in thread
* [TUHS] Did realloc ever zero the new memory?
@ 2015-09-10 19:52 David
  2015-09-10 20:10 ` Jim Capp
  2015-09-11  0:13 ` Dave Horsfall
  0 siblings, 2 replies; 26+ messages in thread
From: David @ 2015-09-10 19:52 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 329 bytes --]

I’ve just had a discussion with my boss about this and he claimed that it did at one point and I said it hasn’t in all the unix versions I’ve ever played with (v6, v7, sys III, V, BSD 2, 3, 4, SunOS and Solaris).

My question to this illustrious group is: Did any Unix or Unix like OS ever zero fill on realloc?

	David




^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-09-17  4:42 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-13  0:32 [TUHS] Did realloc ever zero the new memory? Doug McIlroy
2015-09-13  1:15 ` Larry McVoy
2015-09-13  6:09   ` Dave Horsfall
2015-09-14  3:20     ` Greg 'groggy' Lehey
2015-09-17  4:42       ` Jonathan Gevaryahu
2015-09-13  7:06   ` markus schnalke
2015-09-13 10:32     ` Dave Horsfall
2015-09-13 11:06       ` markus schnalke
2015-09-13 12:13     ` Derek Fawcus
2015-09-13 13:45       ` John Cowan
2015-09-13  1:30 ` Random832
2015-09-13  2:29   ` Charles Anthony
     [not found] <1441931343.25526.for-standards-violators@oclsc.org>
2015-09-12  5:16 ` Dave Horsfall
2015-09-12  6:47   ` Greg 'groggy' Lehey
  -- strict thread matches above, loose matches on Subject: below --
2015-09-11 15:41 Norman Wilson
2015-09-11 16:44 ` scj
2015-09-10 19:52 David
2015-09-10 20:10 ` Jim Capp
2015-09-10 20:21   ` Larry McVoy
2015-09-10 20:22     ` David
2015-09-10 20:27       ` Larry McVoy
2015-09-10 20:29         ` David
2015-09-10 20:41     ` Clem Cole
2015-09-11  6:30       ` arnold
2015-09-11 14:36         ` Clem Cole
2015-09-11  0:13 ` Dave Horsfall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).