TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: All
from: jari laaksonen
date: 1995-01-15 02:11:00
subject: realloc in Watcom 10.0a

Is there something wrong with realloc() in Watcom C/C++ 10.0a?

When I run the following program with parameters 2000...3000, my swapfile
starts growing like crazy (from ca. 14 MB to 23 MB even if the size of 2000
DATA items is only 360000 bytes).

Watcom's realloc() is also much slower than IBM's.

/* compile: wcl386 -zp4 test.c */
#include 
#include 
#include 

#define TEXTLEN  128
#define NAMELEN  13
#define EXTLEN   5

typedef struct _data {
  char        text [TEXTLEN];
  char        name [NAMELEN];
  char        ext  [EXTLEN];
  char        *fullname;
  BOOL        binary;
  ULONG       line;
  long        offset;
  ULONG       fattr;
  FTIME       ftime;
  FDATE       fdate;
  ULONG       fsize;
  USHORT      lboxID;
} DATA;

int main (int argc, char **argv)
{
  short  n = 0, i, loop;
  size_t size;
  DATA  *pData;

  if (argc != 2)
    return 1;

  loop = atoi (argv[1]);
  printf ("sizeof (DATA) = %d\n", sizeof (DATA));

  pData = (DATA *) malloc (sizeof (DATA) * (size_t) 65);

  for (i = 0; i < loop; i++)
  {
    n++;
    if (!(n % 64))
    {
      size = sizeof (DATA) * (size_t) (n + 65);
      pData = (DATA *) realloc (pData, size);
      printf ("i = %d, realloc (pData, %d)\n", i, size);
    }
  }

  free (pData);

  return 0;
}

        // Albert  (Team OS/2)
    email: albert{at}sci.fi
           jla{at}to.icl.fi (work)

---
* Origin: Albert's Point/2 in Finland, Europe (2:221/360.20)
SEEN-BY: 12/2442 620/243 624/50 632/348 640/820 690/660 711/409 410 413 430
SEEN-BY: 711/807 808 809 934 942 949 712/353 515 713/888 800/1 7877/2809
@PATH: 221/360 0 220/841 201/2104 109/347 2 7 3615/50 229/2 12/2442 711/409
@PATH: 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.