www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/08/25/02:13:06

Date: Thu, 25 Aug 94 00:17:57 EDT
From: peprbv AT cfa0 DOT harvard DOT edu (Bob Babcock)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: DJGPP problems
Reply-To: babcock AT cfa DOT harvard DOT edu

> I think that available memory is supposed to depend on the sbrk
> setting, not the number of physical pages in use.  It's supposed to
> correspond to allocated memory, not used memory.

Here's the test program which indicates that either it doesn't work this way
or else _go32_dpmi_remaining_physical_memory() is broken.  It calls malloc 9
times, and checks whether the remaining memory decreases by at least as much
as the amount allocated.  (An exact match is not expected because printf()
probably allocates some memory, and the memory allocator has some hidden
overhead.)  Under xms (DOS 5), there is "missing" (or is it extra?) memory,
and the discrepancy gets large if the allocation size specified on the
command line is large.  Using calloc (which zeroes the memory) rather than
malloc makes the numbers add up.  It doesn't matter whether I use go32
1.11maint5, 1.12 or 1.12maint1.
---------------
/* tst_mem.c testing malloc */

#include <dpmi.h>
#include <stdio.h>
#include <malloc.h>

u_long sh_phys(void){
u_long efp;
  efp = _go32_dpmi_remaining_physical_memory();
  printf("phys_mem = %9lu\n",efp);
  return efp;
}

void main(int argc, char **argv)
   {
   char *ptr, *oldptr;
   long delta, tot;
   int i, size;
   u_long pmem;
   size = atoi(argv[1]);
   oldptr = 0; tot = 0;
   printf("tst_mem.c size = %i\n",size);
   pmem = sh_phys();
   for(i=0; i<9; i++)
      {
/*      ptr = calloc(size,1); */  /* this fixes anomolous behavior */
      ptr = malloc(size);
      tot += size;
      delta = ptr - oldptr;
      printf("ptr= %6lx, siz=%7i", (long)ptr,size);
      if(i > 0)
         printf("  delta=  %6lxH = %6ld", delta, delta);
      printf("\n");
      oldptr = ptr;
      size = 1 * size;   /* change multiplier to allocate different sizes */
      };
   pmem -= sh_phys();
   printf("tot = %ld,  diff phys = %lu\n",tot,pmem);
   if (pmem < tot)
      printf("Error: missing = %ld\n",tot-pmem);
   else
      printf("phys delta ok.\n");
   }

- Raw text -


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