home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / compresn / jpegv3sr / jmemdos.h < prev    next >
C/C++ Source or Header  |  1992-03-07  |  6KB  |  136 lines

  1. /*
  2.  * jmemdos.h  (jmemsys.h)
  3.  *
  4.  * Copyright (C) 1992, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This include file defines the interface between the system-independent
  9.  * and system-dependent portions of the JPEG memory manager.  (The system-
  10.  * independent portion is jmemmgr.c; there are several different versions
  11.  * of the system-dependent portion, and of this file for that matter.)
  12.  *
  13.  * This version is suitable for MS-DOS (80x86) implementations.
  14.  */
  15.  
  16.  
  17. /*
  18.  * These two functions are used to allocate and release small chunks of
  19.  * memory (typically the total amount requested through jget_small is
  20.  * no more than 20Kb or so).  Behavior should be the same as for the
  21.  * standard library functions malloc and free; in particular, jget_small
  22.  * returns NULL on failure.  On most systems, these ARE malloc and free.
  23.  * On an 80x86 machine using small-data memory model, these manage near heap.
  24.  */
  25.  
  26. EXTERN void * jget_small PP((size_t sizeofobject));
  27. EXTERN void jfree_small PP((void * object));
  28.  
  29. /*
  30.  * These two functions are used to allocate and release large chunks of
  31.  * memory (up to the total free space designated by jmem_available).
  32.  * The interface is the same as above, except that on an 80x86 machine,
  33.  * far pointers are used.  On other systems these ARE the same as above.
  34.  */
  35.  
  36. #ifdef NEED_FAR_POINTERS    /* typically not needed except on 80x86 */
  37. EXTERN void FAR * jget_large PP((size_t sizeofobject));
  38. EXTERN void jfree_large PP((void FAR * object));
  39. #else
  40. #define jget_large(sizeofobject)    jget_small(sizeofobject)
  41. #define jfree_large(object)        jfree_small(object)
  42. #endif
  43.  
  44. /*
  45.  * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
  46.  * be requested in a single call on jget_large (and jget_small for that
  47.  * matter, but that case should never come into play).  This macro is needed
  48.  * to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
  49.  * On machines with flat address spaces, any large constant may be used here.
  50.  */
  51.  
  52. #define MAX_ALLOC_CHUNK        65400L
  53.  
  54. /*
  55.  * This routine computes the total space available for allocation by
  56.  * jget_large.  If more space than this is needed, backing store will be used.
  57.  * NOTE: any memory already allocated must not be counted.
  58.  *
  59.  * There is a minimum space requirement, corresponding to the minimum
  60.  * feasible buffer sizes; jmemmgr.c will request that much space even if
  61.  * jmem_available returns zero.  The maximum space needed, enough to hold
  62.  * all working storage in memory, is also passed in case it is useful.
  63.  *
  64.  * It is OK for jmem_available to underestimate the space available (that'll
  65.  * just lead to more backing-store access than is really necessary).
  66.  * However, an overestimate will lead to failure.  Hence it's wise to subtract
  67.  * a slop factor from the true available space, especially if jget_small space
  68.  * comes from the same pool.  5% should be enough.
  69.  *
  70.  * On machines with lots of virtual memory, any large constant may be returned.
  71.  * Conversely, zero may be returned to always use the minimum amount of memory.
  72.  */
  73.  
  74. EXTERN long jmem_available PP((long min_bytes_needed, long max_bytes_needed));
  75.  
  76.  
  77. /*
  78.  * This structure holds whatever state is needed to access a single
  79.  * backing-store object.  The read/write/close method pointers are called
  80.  * by jmemmgr.c to manipulate the backing-store object; all other fields
  81.  * are private to the system-dependent backing store routines.
  82.  */
  83.  
  84. #define TEMP_NAME_LENGTH   64    /* max length of a temporary file's name */
  85.  
  86. typedef unsigned short XMSH;    /* type of extended-memory handles */
  87. typedef unsigned short EMSH;    /* type of expanded-memory handles */
  88.  
  89. typedef union {
  90.     short file_handle;    /* DOS file handle if it's a temp file */
  91.     XMSH xms_handle;    /* handle if it's a chunk of XMS */
  92.     EMSH ems_handle;    /* handle if it's a chunk of EMS */
  93.       } handle_union;
  94.  
  95. typedef struct backing_store_struct * backing_store_ptr;
  96.  
  97. typedef struct backing_store_struct {
  98.     /* Methods for reading/writing/closing this backing-store object */
  99.     METHOD(void, read_backing_store, (backing_store_ptr info,
  100.                       void FAR * buffer_address,
  101.                       long file_offset, long byte_count));
  102.     METHOD(void, write_backing_store, (backing_store_ptr info,
  103.                        void FAR * buffer_address,
  104.                        long file_offset, long byte_count));
  105.     METHOD(void, close_backing_store, (backing_store_ptr info));
  106.     /* Private fields for system-dependent backing-store management */
  107.     /* For the MS-DOS environment, we need: */
  108.     handle_union handle;    /* reference to backing-store storage object */
  109.     char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  110.       } backing_store_info;
  111.  
  112. /*
  113.  * Initial opening of a backing-store object.  This must fill in the
  114.  * read/write/close pointers in the object.  The read/write routines
  115.  * may take an error exit if the specified maximum file size is exceeded.
  116.  * (If jmem_available always returns a large value, this routine can just
  117.  * take an error exit.)
  118.  */
  119.  
  120. EXTERN void jopen_backing_store PP((backing_store_ptr info,
  121.                     long total_bytes_needed));
  122.  
  123.  
  124. /*
  125.  * These routines take care of any system-dependent initialization and
  126.  * cleanup required.  The system methods struct address should be saved
  127.  * by jmem_init in case an error exit must be taken.  jmem_term may assume
  128.  * that all requested memory has been freed and that all opened backing-
  129.  * store objects have been closed.
  130.  * NB: jmem_term may be called more than once, and must behave reasonably
  131.  * if that happens.
  132.  */
  133.  
  134. EXTERN void jmem_init PP((external_methods_ptr emethods));
  135. EXTERN void jmem_term PP((void));
  136.