home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / src / pmalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-06  |  2.4 KB  |  84 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: pmalloc.c,v 5.3 1992/12/07 04:28:03 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.3 $   $State: Exp $
  6.  *
  7.  *            Copyright (c) 1988-1992 USENET Community Trust
  8.  *            Copyright (c) 1986,1987 Dave Taylor
  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 5.3  1992/12/07  04:28:03  syd
  18.  * change include from defs to headers as now needs LINES
  19.  * From: Syd
  20.  *
  21.  * Revision 5.2  1992/11/26  00:46:13  syd
  22.  * changes to first change screen back (Raw off) and then issue final
  23.  * error message.
  24.  * From: Syd
  25.  *
  26.  * Revision 5.1  1992/10/03  22:58:40  syd
  27.  * Initial checkin as of 2.4 Release at PL0
  28.  *
  29.  *
  30.  ******************************************************************************/
  31.  
  32. /** This routine contains a cheap permanent version of the malloc call to 
  33.     speed up the initial allocation of the weedout headers and the uuname 
  34.     data.  
  35.  
  36.       This routine is originally from Jim Davis of HP Labs, with some 
  37.     mods by me.
  38. **/
  39.  
  40. #include <stdio.h>
  41. #include "headers.h"
  42. #include "s_elm.h"
  43.  
  44. extern nl_catd elm_msg_cat;    /* message catalog        */
  45. /*VARARGS0*/
  46.  
  47. char *pmalloc(size)
  48. int size; 
  49. {
  50.     /** return the address of a specified block **/
  51.  
  52.     static char *our_block = NULL;
  53.     static int   free_mem  = 0;
  54.  
  55.     char   *return_value;
  56.  
  57.     /** if bigger than our threshold, just do the real thing! **/
  58.  
  59.     if (size > PMALLOC_THRESHOLD) 
  60.        return((char *) malloc(size));
  61.  
  62.     /** if bigger than available space, get more, tossing what's left **/
  63.  
  64.     if (size > free_mem) {
  65.       if ((our_block = (char *) malloc(PMALLOC_BUFFER_SIZE)) == NULL) {
  66.         MoveCursor(LINES,0);
  67.         Raw(OFF);
  68.         fprintf(stderr, catgets(elm_msg_cat, ElmSet, ElmCouldntMallocBytes,
  69.             "\n\nCouldn't malloc %d bytes!!\n\n"),
  70.             PMALLOC_BUFFER_SIZE);
  71.         leave(0);    
  72.           }
  73.       our_block += 4;  /* just for safety, don't give back true address */
  74.       free_mem = PMALLOC_BUFFER_SIZE-4;
  75.     }
  76.     
  77.     return_value  = our_block;    /* get the memory */
  78.     size = ((size+3)/4)*4;        /* Go to quad byte boundary */
  79.     our_block += size;        /* use it up      */
  80.     free_mem  -= size;        /*  and decrement */
  81.  
  82.     return( (char *) return_value);
  83. }
  84.