Path: blob/master/src/java.desktop/share/native/libjavajpeg/jmemsys.h
41149 views
/*1* reserved comment block2* DO NOT REMOVE OR ALTER!3*/4/*5* jmemsys.h6*7* Copyright (C) 1992-1997, Thomas G. Lane.8* This file is part of the Independent JPEG Group's software.9* For conditions of distribution and use, see the accompanying README file.10*11* This include file defines the interface between the system-independent12* and system-dependent portions of the JPEG memory manager. No other13* modules need include it. (The system-independent portion is jmemmgr.c;14* there are several different versions of the system-dependent portion.)15*16* This file works as-is for the system-dependent memory managers supplied17* in the IJG distribution. You may need to modify it if you write a18* custom memory manager. If system-dependent changes are needed in19* this file, the best method is to #ifdef them based on a configuration20* symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR21* and USE_MAC_MEMMGR.22*/232425/* Short forms of external names for systems with brain-damaged linkers. */2627#ifdef NEED_SHORT_EXTERNAL_NAMES28#define jpeg_get_small jGetSmall29#define jpeg_free_small jFreeSmall30#define jpeg_get_large jGetLarge31#define jpeg_free_large jFreeLarge32#define jpeg_mem_available jMemAvail33#define jpeg_open_backing_store jOpenBackStore34#define jpeg_mem_init jMemInit35#define jpeg_mem_term jMemTerm36#endif /* NEED_SHORT_EXTERNAL_NAMES */373839/*40* These two functions are used to allocate and release small chunks of41* memory. (Typically the total amount requested through jpeg_get_small is42* no more than 20K or so; this will be requested in chunks of a few K each.)43* Behavior should be the same as for the standard library functions malloc44* and free; in particular, jpeg_get_small must return NULL on failure.45* On most systems, these ARE malloc and free. jpeg_free_small is passed the46* size of the object being freed, just in case it's needed.47* On an 80x86 machine using small-data memory model, these manage near heap.48*/4950EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));51EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,52size_t sizeofobject));5354/*55* These two functions are used to allocate and release large chunks of56* memory (up to the total free space designated by jpeg_mem_available).57* The interface is the same as above, except that on an 80x86 machine,58* far pointers are used. On most other machines these are identical to59* the jpeg_get/free_small routines; but we keep them separate anyway,60* in case a different allocation strategy is desirable for large chunks.61*/6263EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,64size_t sizeofobject));65EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,66size_t sizeofobject));6768/*69* The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may70* be requested in a single call to jpeg_get_large (and jpeg_get_small for that71* matter, but that case should never come into play). This macro is needed72* to model the 64Kb-segment-size limit of far addressing on 80x86 machines.73* On those machines, we expect that jconfig.h will provide a proper value.74* On machines with 32-bit flat address spaces, any large constant may be used.75*76* NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type77* size_t and will be a multiple of sizeof(align_type).78*/7980#ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */81#define MAX_ALLOC_CHUNK 1000000000L82#endif8384/*85* This routine computes the total space still available for allocation by86* jpeg_get_large. If more space than this is needed, backing store will be87* used. NOTE: any memory already allocated must not be counted.88*89* There is a minimum space requirement, corresponding to the minimum90* feasible buffer sizes; jmemmgr.c will request that much space even if91* jpeg_mem_available returns zero. The maximum space needed, enough to hold92* all working storage in memory, is also passed in case it is useful.93* Finally, the total space already allocated is passed. If no better94* method is available, cinfo->mem->max_memory_to_use - already_allocated95* is often a suitable calculation.96*97* It is OK for jpeg_mem_available to underestimate the space available98* (that'll just lead to more backing-store access than is really necessary).99* However, an overestimate will lead to failure. Hence it's wise to subtract100* a slop factor from the true available space. 5% should be enough.101*102* On machines with lots of virtual memory, any large constant may be returned.103* Conversely, zero may be returned to always use the minimum amount of memory.104*/105106EXTERN(size_t) jpeg_mem_available JPP((j_common_ptr cinfo,107size_t min_bytes_needed,108size_t max_bytes_needed,109size_t already_allocated));110111112/*113* This structure holds whatever state is needed to access a single114* backing-store object. The read/write/close method pointers are called115* by jmemmgr.c to manipulate the backing-store object; all other fields116* are private to the system-dependent backing store routines.117*/118119#define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */120121122#ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */123124typedef unsigned short XMSH; /* type of extended-memory handles */125typedef unsigned short EMSH; /* type of expanded-memory handles */126127typedef union {128short file_handle; /* DOS file handle if it's a temp file */129XMSH xms_handle; /* handle if it's a chunk of XMS */130EMSH ems_handle; /* handle if it's a chunk of EMS */131} handle_union;132133#endif /* USE_MSDOS_MEMMGR */134135#ifdef USE_MAC_MEMMGR /* Mac-specific junk */136#include <Files.h>137#endif /* USE_MAC_MEMMGR */138139140typedef struct backing_store_struct * backing_store_ptr;141142typedef struct backing_store_struct {143/* Methods for reading/writing/closing this backing-store object */144JMETHOD(void, read_backing_store, (j_common_ptr cinfo,145backing_store_ptr info,146void FAR * buffer_address,147long file_offset, long byte_count));148JMETHOD(void, write_backing_store, (j_common_ptr cinfo,149backing_store_ptr info,150void FAR * buffer_address,151long file_offset, long byte_count));152JMETHOD(void, close_backing_store, (j_common_ptr cinfo,153backing_store_ptr info));154155/* Private fields for system-dependent backing-store management */156#ifdef USE_MSDOS_MEMMGR157/* For the MS-DOS manager (jmemdos.c), we need: */158handle_union handle; /* reference to backing-store storage object */159char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */160#else161#ifdef USE_MAC_MEMMGR162/* For the Mac manager (jmemmac.c), we need: */163short temp_file; /* file reference number to temp file */164FSSpec tempSpec; /* the FSSpec for the temp file */165char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */166#else167/* For a typical implementation with temp files, we need: */168FILE * temp_file; /* stdio reference to temp file */169char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */170#endif171#endif172} backing_store_info;173174175/*176* Initial opening of a backing-store object. This must fill in the177* read/write/close pointers in the object. The read/write routines178* may take an error exit if the specified maximum file size is exceeded.179* (If jpeg_mem_available always returns a large value, this routine can180* just take an error exit.)181*/182183EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,184backing_store_ptr info,185long total_bytes_needed));186187188/*189* These routines take care of any system-dependent initialization and190* cleanup required. jpeg_mem_init will be called before anything is191* allocated (and, therefore, nothing in cinfo is of use except the error192* manager pointer). It should return a suitable default value for193* max_memory_to_use; this may subsequently be overridden by the surrounding194* application. (Note that max_memory_to_use is only important if195* jpeg_mem_available chooses to consult it ... no one else will.)196* jpeg_mem_term may assume that all requested memory has been freed and that197* all opened backing-store objects have been closed.198*/199200EXTERN(size_t) jpeg_mem_init JPP((j_common_ptr cinfo));201EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));202203204