public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: x*alloc optimizations
@ 1998-05-20 19:03 Michael Meissner
  1998-05-20 19:03 ` Ulrich Drepper
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Meissner @ 1998-05-20 19:03 UTC (permalink / raw)
  To: meissner, meyering; +Cc: drepper, egcs

| Michael Meissner <meissner@cygnus.com> writes:
| | This is an unneeded micro-optimization.  I would rather burn the 2-3
| | instructions for every xmalloc call than add a bunch of configure support and
| | ifdefs to complicate the code.  Especially for Canadian crosses where you can't
| | test the behavior of the runtime system.  Another problem is that when GCC
| | configured it, malloc/calloc/realloc behaved in one fashion, but when the user
| | put the binary compiler on his/her system, the system malloc in the shared
| | library now behaves differently.
|
| I admit it may not be worth it, but it can be done without
| complicating the code.  Uses of *alloc functions don't change
| at all, and the only ifdefs I added (when I did this for fileutils)
| were in the replacement lib/*alloc.c functions.  The m4 tests assume
| *alloc are broken when cross compiling.

While linux gnulibc{1,2} may or may not change the behavior of malloc, I have
witnessed this at OSF, where one revision of OSF/1 had malloc do one behavior
(crash on NULL pointer to realloc or return NULL, I forget which), and the next
revision did another behavior (return unique pointer).  I as supplier of
compiler binaries then would have my releases not work, if I built the compiler
on one revision, and had users on the other revision tried to use the
compiler.  Depending on a configure test for malloc/realloc behavior is utterly
dangerous for providers of binary software.

--
Michael Meissner, Cygnus Solutions (Massachusetts office)
4th floor, 955 Massachusetts Avenue, Cambridge, MA 02139, USA
meissner@cygnus.com,	617-354-5416 (office),	617-354-7161 (fax)


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: x*alloc optimizations
@ 1998-05-20 12:48 Michael Meissner
  1998-05-20 19:03 ` Ulrich Drepper
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Meissner @ 1998-05-20 12:48 UTC (permalink / raw)
  To: drepper; +Cc: egcs

| Michael Meissner <meissner@cygnus.com> writes:
|
| > I as supplier of compiler binaries then would have my releases not
| > work, if I built the compiler on one revision, and had users on the
| > other revision tried to use the compiler.  Depending on a configure
| > test for malloc/realloc behavior is utterly dangerous for providers
| > of binary software.
|
| Come on!  This is no arbitrary test.  This is the test for ISO C
| compliance and no vendor will dare to make an compliant library
| suddenly uncompliant.

There are loads of uncomplaint systems.  Also ISO C has two different
behaviors (return NULL or return a unique pointer).  If you test for one, a
system vendor may change his/her implementation to do the other behavior
without breaking ISO C conformance.

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: x*alloc optimizations
@ 1998-05-18 18:06 Michael Meissner
  1998-05-20  7:09 ` Jim Meyering
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Meissner @ 1998-05-18 18:06 UTC (permalink / raw)
  To: drepper; +Cc: egcs

| law@cygnus.com (Jeffrey A Law) writes:
|
| > I quickly scanned your patch for any problems this creates, but didn't
| > find any.  However, we should probably fix xrealloc to avoid losing if
| > a zero sized request is made.
|
| But please fix this system dependent.  I.e., add a configure test for
| this non-ISO C behaviour and don't let normal systems do the same work
| twice (since their realloc implementation again checks for NULL).

This is an unneeded micro-optimization.  I would rather burn the 2-3
instructions for every xmalloc call than add a bunch of configure support and
ifdefs to complicate the code.  Especially for Canadian crosses where you can't
test the behavior of the runtime system.  Another problem is that when GCC
configured it, malloc/calloc/realloc behaved in one fashion, but when the user
put the binary compiler on his/her system, the system malloc in the shared
library now behaves differently.

--
Michael Meissner, Cygnus Solutions (Massachusetts office)
4th floor, 955 Massachusetts Avenue, Cambridge, MA 02139, USA
meissner@cygnus.com,	617-354-5416 (office),	617-354-7161 (fax)


^ permalink raw reply	[flat|nested] 12+ messages in thread
* x*alloc optimizations
@ 1998-05-16 22:35 Richard Henderson
  1998-05-18  2:09 ` Jeffrey A Law
       [not found] ` <25274.895468839.cygnus.egcs@hurl.cygnus.com>
  0 siblings, 2 replies; 12+ messages in thread
From: Richard Henderson @ 1998-05-16 22:35 UTC (permalink / raw)
  To: egcs

Two things.  

  (1) Since we define xrealloc, we can trust it to do the right thing
      when given a NULL initial argument.  

  (2) Using calloc instead of malloc+bzero can be more efficient.  At
      least glibc's calloc knows that space newly acquired from the
      system is already zero.  This is particularaly relevant to the
      large memory blocks gcc tends to allocate during optimization.


r~

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

end of thread, other threads:[~1998-05-21  0:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-20 19:03 x*alloc optimizations Michael Meissner
1998-05-20 19:03 ` Ulrich Drepper
1998-05-21  0:51   ` Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
1998-05-20 12:48 Michael Meissner
1998-05-20 19:03 ` Ulrich Drepper
1998-05-18 18:06 Michael Meissner
1998-05-20  7:09 ` Jim Meyering
1998-05-16 22:35 Richard Henderson
1998-05-18  2:09 ` Jeffrey A Law
     [not found] ` <25274.895468839.cygnus.egcs@hurl.cygnus.com>
1998-05-18  9:58   ` Ulrich Drepper
1998-05-18 22:49     ` Jeffrey A Law
1998-05-20  8:42       ` Jim Meyering

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 read-only IMAP folder(s) and NNTP newsgroup(s).