www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/07/09:44:25

Date: Thu, 7 Nov 1996 16:27:44 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "John M. Aldrich" <fighteer AT cs DOT com>
Cc: DR TE$TH & THE ELECTRIC MAYHEM <ronb AT cc DOT usu DOT edu>, djgpp AT delorie DOT com
Subject: Re: max=32768 pointers?
In-Reply-To: <327FF9A5.1D0D@cs.com>
Message-Id: <Pine.SUN.3.91.961107161753.3950C-100000@is>
Mime-Version: 1.0

On Tue, 5 Nov 1996, John M. Aldrich wrote:

> DR TE$TH & THE ELECTRIC MAYHEM wrote:
> > 
> > I have heard that you cannot allocate 32,768+ pointers without first freeing
> > some of them.  Is this true?  If so, what is the cause?  I could probably
> > figure a workaround if I knew what was stonewalling me.
> 
> your memory requirements.  The absolute upper limit you should observe
> is no more than 200 or so separate allocations; any more and you're
> doing something badly wrong.

Both of the numbers above (32,768 and 200) are in general incorrect. 
First, any such discussion is specific to a certain DPMI host.  If we are
talking about CWSDPMI, then the latest release 3 is documented to be able
to allocate at least 21MBytes in small chunks; the small test program
below allocates about 28MBytes in 1KB chunks before `calloc' fails.  I
changed the chunk size to 500 bytes, and was able to allocate at least
40,000 such chunks.  So you don't need to worry about any limits as long
as you don't allocate more than 20MBytes;  changing the default parameters
of CWSDPMI with CWSPARAM can push that limit still further. 

Btw, QDPMI let me allocate 80MBytes in 2KB chunks (on a 64MB machine) and 
never puked.

------------------------------ alloctst.c --------------------------------
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  char *ptable[40000];
  int imax = sizeof (ptable) / sizeof (ptable[0]);
  int i = 0;

  while (i < imax)
    {
      ptable[i] = (char *) calloc (1000, 1);
      if (!ptable[i])
        break;
      printf ("Alloced %d buffers\n", ++i);
    }
  return 0;
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019