0N/A/*
0N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
0N/A * jmemsys.h
0N/A *
0N/A * Copyright (C) 1992-1997, Thomas G. Lane.
0N/A * This file is part of the Independent JPEG Group's software.
0N/A * For conditions of distribution and use, see the accompanying README file.
0N/A *
0N/A * This include file defines the interface between the system-independent
0N/A * and system-dependent portions of the JPEG memory manager. No other
0N/A * modules need include it. (The system-independent portion is jmemmgr.c;
0N/A * there are several different versions of the system-dependent portion.)
0N/A *
0N/A * This file works as-is for the system-dependent memory managers supplied
0N/A * in the IJG distribution. You may need to modify it if you write a
0N/A * custom memory manager. If system-dependent changes are needed in
0N/A * this file, the best method is to #ifdef them based on a configuration
0N/A * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR
0N/A * and USE_MAC_MEMMGR.
0N/A */
0N/A
0N/A
0N/A/* Short forms of external names for systems with brain-damaged linkers. */
0N/A
0N/A#ifdef NEED_SHORT_EXTERNAL_NAMES
0N/A#define jpeg_get_small jGetSmall
0N/A#define jpeg_free_small jFreeSmall
0N/A#define jpeg_get_large jGetLarge
0N/A#define jpeg_free_large jFreeLarge
0N/A#define jpeg_mem_available jMemAvail
0N/A#define jpeg_open_backing_store jOpenBackStore
0N/A#define jpeg_mem_init jMemInit
0N/A#define jpeg_mem_term jMemTerm
0N/A#endif /* NEED_SHORT_EXTERNAL_NAMES */
0N/A
0N/A
0N/A/*
0N/A * These two functions are used to allocate and release small chunks of
0N/A * memory. (Typically the total amount requested through jpeg_get_small is
0N/A * no more than 20K or so; this will be requested in chunks of a few K each.)
0N/A * Behavior should be the same as for the standard library functions malloc
0N/A * and free; in particular, jpeg_get_small must return NULL on failure.
0N/A * On most systems, these ARE malloc and free. jpeg_free_small is passed the
0N/A * size of the object being freed, just in case it's needed.
0N/A * On an 80x86 machine using small-data memory model, these manage near heap.
0N/A */
0N/A
0N/AEXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
0N/AEXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
0N/A size_t sizeofobject));
0N/A
0N/A/*
0N/A * These two functions are used to allocate and release large chunks of
0N/A * memory (up to the total free space designated by jpeg_mem_available).
0N/A * The interface is the same as above, except that on an 80x86 machine,
0N/A * far pointers are used. On most other machines these are identical to
0N/A * the jpeg_get/free_small routines; but we keep them separate anyway,
0N/A * in case a different allocation strategy is desirable for large chunks.
0N/A */
0N/A
0N/AEXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
0N/A size_t sizeofobject));
0N/AEXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
0N/A size_t sizeofobject));
0N/A
0N/A/*
0N/A * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
0N/A * be requested in a single call to jpeg_get_large (and jpeg_get_small for that
0N/A * matter, but that case should never come into play). This macro is needed
0N/A * to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
0N/A * On those machines, we expect that jconfig.h will provide a proper value.
0N/A * On machines with 32-bit flat address spaces, any large constant may be used.
0N/A *
0N/A * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
0N/A * size_t and will be a multiple of sizeof(align_type).
0N/A */
0N/A
0N/A#ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
0N/A#define MAX_ALLOC_CHUNK 1000000000L
0N/A#endif
0N/A
0N/A/*
0N/A * This routine computes the total space still available for allocation by
0N/A * jpeg_get_large. If more space than this is needed, backing store will be
0N/A * used. NOTE: any memory already allocated must not be counted.
0N/A *
0N/A * There is a minimum space requirement, corresponding to the minimum
0N/A * feasible buffer sizes; jmemmgr.c will request that much space even if
0N/A * jpeg_mem_available returns zero. The maximum space needed, enough to hold
0N/A * all working storage in memory, is also passed in case it is useful.
0N/A * Finally, the total space already allocated is passed. If no better
0N/A * method is available, cinfo->mem->max_memory_to_use - already_allocated
0N/A * is often a suitable calculation.
0N/A *
0N/A * It is OK for jpeg_mem_available to underestimate the space available
0N/A * (that'll just lead to more backing-store access than is really necessary).
0N/A * However, an overestimate will lead to failure. Hence it's wise to subtract
0N/A * a slop factor from the true available space. 5% should be enough.
0N/A *
0N/A * On machines with lots of virtual memory, any large constant may be returned.
0N/A * Conversely, zero may be returned to always use the minimum amount of memory.
0N/A */
0N/A
3538N/AEXTERN(size_t) jpeg_mem_available JPP((j_common_ptr cinfo,
3538N/A size_t min_bytes_needed,
3538N/A size_t max_bytes_needed,
3538N/A size_t already_allocated));
0N/A
0N/A
0N/A/*
0N/A * This structure holds whatever state is needed to access a single
0N/A * backing-store object. The read/write/close method pointers are called
0N/A * by jmemmgr.c to manipulate the backing-store object; all other fields
0N/A * are private to the system-dependent backing store routines.
0N/A */
0N/A
0N/A#define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
0N/A
0N/A
0N/A#ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
0N/A
0N/Atypedef unsigned short XMSH; /* type of extended-memory handles */
0N/Atypedef unsigned short EMSH; /* type of expanded-memory handles */
0N/A
0N/Atypedef union {
0N/A short file_handle; /* DOS file handle if it's a temp file */
0N/A XMSH xms_handle; /* handle if it's a chunk of XMS */
0N/A EMSH ems_handle; /* handle if it's a chunk of EMS */
0N/A} handle_union;
0N/A
0N/A#endif /* USE_MSDOS_MEMMGR */
0N/A
0N/A#ifdef USE_MAC_MEMMGR /* Mac-specific junk */
0N/A#include <Files.h>
0N/A#endif /* USE_MAC_MEMMGR */
0N/A
0N/A
0N/Atypedef struct backing_store_struct * backing_store_ptr;
0N/A
0N/Atypedef struct backing_store_struct {
0N/A /* Methods for reading/writing/closing this backing-store object */
0N/A JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
0N/A backing_store_ptr info,
0N/A void FAR * buffer_address,
0N/A long file_offset, long byte_count));
0N/A JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
0N/A backing_store_ptr info,
0N/A void FAR * buffer_address,
0N/A long file_offset, long byte_count));
0N/A JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
0N/A backing_store_ptr info));
0N/A
0N/A /* Private fields for system-dependent backing-store management */
0N/A#ifdef USE_MSDOS_MEMMGR
0N/A /* For the MS-DOS manager (jmemdos.c), we need: */
0N/A handle_union handle; /* reference to backing-store storage object */
0N/A char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
0N/A#else
0N/A#ifdef USE_MAC_MEMMGR
0N/A /* For the Mac manager (jmemmac.c), we need: */
0N/A short temp_file; /* file reference number to temp file */
0N/A FSSpec tempSpec; /* the FSSpec for the temp file */
0N/A char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
0N/A#else
0N/A /* For a typical implementation with temp files, we need: */
0N/A FILE * temp_file; /* stdio reference to temp file */
0N/A char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
0N/A#endif
0N/A#endif
0N/A} backing_store_info;
0N/A
0N/A
0N/A/*
0N/A * Initial opening of a backing-store object. This must fill in the
0N/A * read/write/close pointers in the object. The read/write routines
0N/A * may take an error exit if the specified maximum file size is exceeded.
0N/A * (If jpeg_mem_available always returns a large value, this routine can
0N/A * just take an error exit.)
0N/A */
0N/A
0N/AEXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
0N/A backing_store_ptr info,
0N/A long total_bytes_needed));
0N/A
0N/A
0N/A/*
0N/A * These routines take care of any system-dependent initialization and
0N/A * cleanup required. jpeg_mem_init will be called before anything is
0N/A * allocated (and, therefore, nothing in cinfo is of use except the error
0N/A * manager pointer). It should return a suitable default value for
0N/A * max_memory_to_use; this may subsequently be overridden by the surrounding
0N/A * application. (Note that max_memory_to_use is only important if
0N/A * jpeg_mem_available chooses to consult it ... no one else will.)
0N/A * jpeg_mem_term may assume that all requested memory has been freed and that
0N/A * all opened backing-store objects have been closed.
0N/A */
0N/A
3538N/AEXTERN(size_t) jpeg_mem_init JPP((j_common_ptr cinfo));
0N/AEXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));