home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lr.zip / M.INC < prev    next >
Text File  |  1993-05-15  |  3KB  |  77 lines

  1. /*
  2. _____________________________________________________________
  3. Memory allocation structures
  4. Philip R Brenan,  Transcendental Automation,  1993,  800-FOR-PHIL
  5. _____________________________________________________________
  6. */
  7. #ifndef M_INC
  8. #define M_INC
  9.  
  10. #ifdef M_MAIN
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #define INCL_DOSMEMMGR
  15. #include <os2.h>
  16. #endif
  17.  
  18. #ifndef   X_INC
  19. #include "x.inc"
  20. #endif
  21. /*
  22. _____________________________________________________________
  23. Memory allocation constants
  24. _____________________________________________________________
  25. */
  26. #define m_put_count          1 // More than one area in condensed version
  27. #define m_put_file           2 // Unable to open save file for writing
  28. #define m_get_file           3 // Unable to open save file for reading
  29. #define m_size long int        // Integer large enough to hold maximum memory amount
  30. #define m_page_size       4096 // Page size
  31. /*
  32. _____________________________________________________________
  33. Memory allocation structures
  34. _____________________________________________________________
  35. */
  36. typedef struct M                       // Memory chain
  37.  {XL        x;                         // Memory list
  38.   m_size    size;                      // Size of allocation - sizeof(m)
  39.   struct m *last;                      // Current area
  40.   m_size    alloc_used;                // Used memory (including control areas)
  41.   m_size    alloc_bytes;               // Allocated bytes (including control areas)
  42.   m_size    alloc_areas;               // Allocated areas
  43.   m_size    allocs;                    // Number of user allocations
  44.  } M;
  45.  
  46. typedef struct m                       // Memory area
  47.  {Xl     x;                            // Memory list
  48.   m_size size;                         // Size of usable area
  49.   m_size alloc;                        // Amount allocated for this area (include control blocks)
  50.   void  *at;                           // Next allocation
  51.  } m;
  52. /*
  53. _____________________________________________________________
  54. Memory management macros
  55. _____________________________________________________________
  56. */
  57. #define m_alloc_str(m, s)     strcpy (m_alloc(m, strlen(s) + 1), s)
  58. #define m_alloc_strn(m, s, n) strncpy(m_alloc(m, n + 1),         s, n + 1)
  59. #define m_alloc_struct(S, s, size) {M *m = m_open(sizeof(S) + (size)); s = m_alloc(m, sizeof(S)); s->m = m;}
  60. /*
  61. _____________________________________________________________
  62. Memory procedure declarations
  63. _____________________________________________________________
  64. */
  65. M    *m_open (       m_size size);
  66. void *m_alloc(M  *p, m_size size);
  67. void  m_close(M  *p);
  68. int   m_put  (M  *p, void *u,  char *ds);
  69. int   m_get  (M **p, void **u, char *ds);
  70.  
  71. void  m_test (void);
  72.  
  73. void *m_alloc_area(m_size size);
  74. void  m_free_area (void  *at);
  75.  
  76. #endif
  77.