home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk12 / ted / tedmem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-20  |  2.1 KB  |  77 lines

  1. /***************************************************************************
  2.  
  3.     Tedmem.c
  4.  
  5.     Created by Microsoft Corporation, IBM Corporation 1989
  6.  
  7. ----------------------------------------------------------------------------
  8.  
  9.         This file contains the functions nessesary to allocate and free
  10.         memory blocks.  It is implemented to return pointers and thus
  11.         does not tie the application to Selector/Offsets etc.
  12.  
  13. ***************************************************************************/
  14.  
  15.  
  16. #define INCL_DOS
  17.  
  18. #include <os2.h>
  19. #include "tedmem.h"
  20.  
  21.  
  22.  
  23.  
  24. /***************************************************************************
  25.  
  26.     MyAllocMem - This procedure allocates a buffer of a requested length.
  27.  
  28.         Return - FALSE if succesful otherwise TRUE
  29.  
  30. ***************************************************************************/
  31.  
  32.  
  33. APIRET APIENTRY MyAllocMem( PVOID *ppch,    /* Pointer to memory        */
  34.                             ULONG usBytes,  /* Number of bytes to alloc */
  35.                             ULONG ulDum1  ) /* Dummy                    */
  36. {
  37.  
  38.     APIRET apiRetVal;                       /* Return Value (FALSE = success*/
  39.     PCHAR pchTemp;                          /* Temp ptr used to alloc mem   */
  40.  
  41.  
  42.     if ( (apiRetVal = (APIRET) DosAllocSeg( (USHORT) usBytes,
  43.                                             &SELECTOROF( pchTemp ),
  44.                                 0 ) ) == (APIRET) 0 )
  45.  
  46.     {
  47.  
  48.     /* Success!! */
  49.  
  50.         OFFSETOF( pchTemp ) = 0;            /* Set offset of selector to 0  */
  51.         *ppch = pchTemp;                    /* Set passed in ptr to new mem */
  52.     }
  53.  
  54.  
  55.     return ( apiRetVal );
  56.  
  57. }
  58.  
  59.  
  60.  
  61. /***************************************************************************
  62.  
  63.     MyFreeMem - This procedure frees a buffer that was previously allocated
  64.                 with MyAllocMem.
  65.  
  66.        Return - FALSE if succesful otherwise TRUE
  67.  
  68. ***************************************************************************/
  69.  
  70.  
  71. APIRET APIENTRY MyFreeMem( PVOID pvTemp )
  72. {
  73.  
  74.     return ( APIRET) DosFreeSeg( SELECTOROF( pvTemp ) );
  75.  
  76. }
  77.