home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / aix-rs6000 / elm2.3.11.AIX3.1.5.Z / elm2.3.11.AIX3.1.5 / src / pmalloc.c < prev    next >
C/C++ Source or Header  |  1990-04-28  |  2KB  |  70 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: pmalloc.c,v 4.1 90/04/28 22:43:43 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log:    pmalloc.c,v $
  17.  * Revision 4.1  90/04/28  22:43:43  syd
  18.  * checkin of Elm 2.3 as of Release PL0
  19.  * 
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** This routine contains a cheap permanent version of the malloc call to 
  24.     speed up the initial allocation of the weedout headers and the uuname 
  25.     data.  
  26.  
  27.       This routine is originally from Jim Davis of HP Labs, with some 
  28.     mods by me.
  29. **/
  30.  
  31. #include <stdio.h>
  32. #include "defs.h"
  33.  
  34. /*VARARGS0*/
  35.  
  36. char *pmalloc(size)
  37. int size; 
  38. {
  39.     /** return the address of a specified block **/
  40.  
  41.     static char *our_block = NULL;
  42.     static int   free_mem  = 0;
  43.  
  44.     char   *return_value, *malloc();
  45.  
  46.     /** if bigger than our threshold, just do the real thing! **/
  47.  
  48.     if (size > PMALLOC_THRESHOLD) 
  49.        return(malloc(size));
  50.  
  51.     /** if bigger than available space, get more, tossing what's left **/
  52.  
  53.     if (size > free_mem) {
  54.       if ((our_block = malloc(PMALLOC_BUFFER_SIZE)) == NULL) {
  55.         fprintf(stderr, "\n\r\n\rCouldn't malloc %d bytes!!\n\r\n\r",
  56.             PMALLOC_BUFFER_SIZE);
  57.         leave();    
  58.           }
  59.       our_block += 4;  /* just for safety, don't give back true address */
  60.       free_mem = PMALLOC_BUFFER_SIZE-4;
  61.     }
  62.     
  63.     return_value  = our_block;    /* get the memory */
  64.     size = ((size+3)/4)*4;        /* Go to quad byte boundary */
  65.     our_block += size;        /* use it up      */
  66.     free_mem  -= size;        /*  and decrement */
  67.  
  68.     return( (char *) return_value);
  69. }
  70.