libfortran: Don't zero internally allocated memory (performance issue, PR 21324)

Thomas Koenig Thomas.Koenig@online.de
Mon May 2 19:55:00 GMT 2005


I wrote:

> OK to commit?

Of course, this is better with the actual patch attached...

> 	Thomas
> 
> 2005-05-02  Thomas Koenig  <Thomas.Koenig@online.de>
> 
> 	PR libfortran/21324
> 	* runtime/memory.c:  Don't define GFC_CLEAR_MEMORY (it's a
> 	performance hog).
> 	* io/open.c (new_unit): Zero freshly allocated memory for
> 	unit structure.
> 	* io/unit.c (init_units):  Zero freshly allocated memory for
> 	STDIN, STDOUT and STDERR.
> 	* io/unix.c (open_internal):  Zero freshly allocated memory
> 	for unix_stream.
-------------- next part --------------
Index: runtime/memory.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/runtime/memory.c,v
retrieving revision 1.6
diff -c -p -r1.6 memory.c
*** runtime/memory.c	12 Jan 2005 21:27:31 -0000	1.6
--- runtime/memory.c	2 May 2005 19:32:19 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 36,42 ****
     return memory that is guaranteed to be set to zero.  This can have
     a severe efficiency penalty, so it should never be set if good
     performance is desired, but it can help when you're debugging code.  */
! #define GFC_CLEAR_MEMORY
  
  /* If GFC_CHECK_MEMORY is defined, we do some sanity checks at runtime.
     This causes small overhead, but again, it also helps debugging.  */
--- 36,42 ----
     return memory that is guaranteed to be set to zero.  This can have
     a severe efficiency penalty, so it should never be set if good
     performance is desired, but it can help when you're debugging code.  */
! /* #define GFC_CLEAR_MEMORY */
  
  /* If GFC_CHECK_MEMORY is defined, we do some sanity checks at runtime.
     This causes small overhead, but again, it also helps debugging.  */
Index: io/open.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/open.c,v
retrieving revision 1.12
diff -c -p -r1.12 open.c
*** io/open.c	29 Mar 2005 08:37:32 -0000	1.12
--- io/open.c	2 May 2005 19:32:25 -0000
*************** new_unit (unit_flags * flags)
*** 351,356 ****
--- 351,357 ----
    /* Create the unit structure.  */
  
    u = get_mem (sizeof (gfc_unit) + ioparm.file_len);
+   memset (u, '\0', sizeof (gfc_unit) + ioparm.file_len);
  
    u->unit_number = ioparm.unit;
    u->s = s;
Index: io/unit.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/unit.c,v
retrieving revision 1.8
diff -c -p -r1.8 unit.c
*** io/unit.c	23 Jan 2005 00:14:30 -0000	1.8
--- io/unit.c	2 May 2005 19:32:29 -0000
*************** init_units (void)
*** 295,300 ****
--- 295,301 ----
    if (options.stdin_unit >= 0)
      {				/* STDIN */
        u = get_mem (sizeof (gfc_unit));
+       memset (u, '\0', sizeof (gfc_unit));
  
        u->unit_number = options.stdin_unit;
        u->s = input_stream ();
*************** init_units (void)
*** 316,321 ****
--- 317,323 ----
    if (options.stdout_unit >= 0)
      {				/* STDOUT */
        u = get_mem (sizeof (gfc_unit));
+       memset (u, '\0', sizeof (gfc_unit));
  
        u->unit_number = options.stdout_unit;
        u->s = output_stream ();
*************** init_units (void)
*** 337,342 ****
--- 339,345 ----
    if (options.stderr_unit >= 0)
      {				/* STDERR */
        u = get_mem (sizeof (gfc_unit));
+       memset (u, '\0', sizeof (gfc_unit));
  
        u->unit_number = options.stderr_unit;
        u->s = error_stream ();
Index: io/unix.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/unix.c,v
retrieving revision 1.22
diff -c -p -r1.22 unix.c
*** io/unix.c	29 Apr 2005 14:24:04 -0000	1.22
--- io/unix.c	2 May 2005 19:32:31 -0000
*************** open_internal (char *base, int length)
*** 870,875 ****
--- 870,876 ----
    unix_stream *s;
  
    s = get_mem (sizeof (unix_stream));
+   memset (s, '\0', sizeof (unix_stream));
  
    s->buffer = base;
    s->buffer_offset = 0;
*************** fd_to_stream (int fd, int prot)
*** 898,903 ****
--- 899,905 ----
    unix_stream *s;
  
    s = get_mem (sizeof (unix_stream));
+   memset (s, '\0', sizeof (unix_stream));
  
    s->fd = fd;
    s->buffer_offset = 0;


More information about the Fortran mailing list