Remove 'oldcode'
[oweals/cde.git] / cde / lib / DtHelp / jpeg / jmemsys.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: jmemsys.h /main/2 1996/05/09 03:52:46 drk $ */
24 /*
25  * jmemsys.h
26  *
27  * Copyright (C) 1992-1996, Thomas G. Lane.
28  * This file is part of the Independent JPEG Group's software.
29  * For conditions of distribution and use, see the accompanying README file.
30  *
31  * This include file defines the interface between the system-independent
32  * and system-dependent portions of the JPEG memory manager.  No other
33  * modules need include it.  (The system-independent portion is jmemmgr.c;
34  * there are several different versions of the system-dependent portion.)
35  *
36  * This file works as-is for the system-dependent memory managers supplied
37  * in the IJG distribution.  You may need to modify it if you write a
38  * custom memory manager.  If system-dependent changes are needed in
39  * this file, the best method is to #ifdef them based on a configuration
40  * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR.
41  */
42
43
44 /* Short forms of external names for systems with brain-damaged linkers. */
45
46 #ifdef NEED_SHORT_EXTERNAL_NAMES
47 #define jpeg_get_small          jGetSmall
48 #define jpeg_free_small         jFreeSmall
49 #define jpeg_get_large          jGetLarge
50 #define jpeg_free_large         jFreeLarge
51 #define jpeg_mem_available      jMemAvail
52 #define jpeg_open_backing_store jOpenBackStore
53 #define jpeg_mem_init           jMemInit
54 #define jpeg_mem_term           jMemTerm
55 #endif /* NEED_SHORT_EXTERNAL_NAMES */
56
57
58 /*
59  * These two functions are used to allocate and release small chunks of
60  * memory.  (Typically the total amount requested through jpeg_get_small is
61  * no more than 20K or so; this will be requested in chunks of a few K each.)
62  * Behavior should be the same as for the standard library functions malloc
63  * and free; in particular, jpeg_get_small must return NULL on failure.
64  * On most systems, these ARE malloc and free.  jpeg_free_small is passed the
65  * size of the object being freed, just in case it's needed.
66  * On an 80x86 machine using small-data memory model, these manage near heap.
67  */
68
69 EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
70 EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
71                                   size_t sizeofobject));
72
73 /*
74  * These two functions are used to allocate and release large chunks of
75  * memory (up to the total free space designated by jpeg_mem_available).
76  * The interface is the same as above, except that on an 80x86 machine,
77  * far pointers are used.  On most other machines these are identical to
78  * the jpeg_get/free_small routines; but we keep them separate anyway,
79  * in case a different allocation strategy is desirable for large chunks.
80  */
81
82 EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
83                                        size_t sizeofobject));
84 EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
85                                   size_t sizeofobject));
86
87 /*
88  * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
89  * be requested in a single call to jpeg_get_large (and jpeg_get_small for that
90  * matter, but that case should never come into play).  This macro is needed
91  * to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
92  * On those machines, we expect that jconfig.h will provide a proper value.
93  * On machines with 32-bit flat address spaces, any large constant may be used.
94  *
95  * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
96  * size_t and will be a multiple of sizeof(align_type).
97  */
98
99 #ifndef MAX_ALLOC_CHUNK         /* may be overridden in jconfig.h */
100 #define MAX_ALLOC_CHUNK  1000000000L
101 #endif
102
103 /*
104  * This routine computes the total space still available for allocation by
105  * jpeg_get_large.  If more space than this is needed, backing store will be
106  * used.  NOTE: any memory already allocated must not be counted.
107  *
108  * There is a minimum space requirement, corresponding to the minimum
109  * feasible buffer sizes; jmemmgr.c will request that much space even if
110  * jpeg_mem_available returns zero.  The maximum space needed, enough to hold
111  * all working storage in memory, is also passed in case it is useful.
112  * Finally, the total space already allocated is passed.  If no better
113  * method is available, cinfo->mem->max_memory_to_use - already_allocated
114  * is often a suitable calculation.
115  *
116  * It is OK for jpeg_mem_available to underestimate the space available
117  * (that'll just lead to more backing-store access than is really necessary).
118  * However, an overestimate will lead to failure.  Hence it's wise to subtract
119  * a slop factor from the true available space.  5% should be enough.
120  *
121  * On machines with lots of virtual memory, any large constant may be returned.
122  * Conversely, zero may be returned to always use the minimum amount of memory.
123  */
124
125 EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
126                                      long min_bytes_needed,
127                                      long max_bytes_needed,
128                                      long already_allocated));
129
130
131 /*
132  * This structure holds whatever state is needed to access a single
133  * backing-store object.  The read/write/close method pointers are called
134  * by jmemmgr.c to manipulate the backing-store object; all other fields
135  * are private to the system-dependent backing store routines.
136  */
137
138 #define TEMP_NAME_LENGTH   64   /* max length of a temporary file's name */
139
140 #ifdef USE_MSDOS_MEMMGR         /* DOS-specific junk */
141
142 typedef unsigned short XMSH;    /* type of extended-memory handles */
143 typedef unsigned short EMSH;    /* type of expanded-memory handles */
144
145 typedef union {
146   short file_handle;            /* DOS file handle if it's a temp file */
147   XMSH xms_handle;              /* handle if it's a chunk of XMS */
148   EMSH ems_handle;              /* handle if it's a chunk of EMS */
149 } handle_union;
150
151 #endif /* USE_MSDOS_MEMMGR */
152
153 typedef struct backing_store_struct * backing_store_ptr;
154
155 typedef struct backing_store_struct {
156   /* Methods for reading/writing/closing this backing-store object */
157   JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
158                                      backing_store_ptr info,
159                                      void FAR * buffer_address,
160                                      long file_offset, long byte_count));
161   JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
162                                       backing_store_ptr info,
163                                       void FAR * buffer_address,
164                                       long file_offset, long byte_count));
165   JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
166                                       backing_store_ptr info));
167
168   /* Private fields for system-dependent backing-store management */
169 #ifdef USE_MSDOS_MEMMGR
170   /* For the MS-DOS manager (jmemdos.c), we need: */
171   handle_union handle;          /* reference to backing-store storage object */
172   char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
173 #else
174   /* For a typical implementation with temp files, we need: */
175   FILE * temp_file;             /* stdio reference to temp file */
176   char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
177 #endif
178 } backing_store_info;
179
180 /*
181  * Initial opening of a backing-store object.  This must fill in the
182  * read/write/close pointers in the object.  The read/write routines
183  * may take an error exit if the specified maximum file size is exceeded.
184  * (If jpeg_mem_available always returns a large value, this routine can
185  * just take an error exit.)
186  */
187
188 EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
189                                           backing_store_ptr info,
190                                           long total_bytes_needed));
191
192
193 /*
194  * These routines take care of any system-dependent initialization and
195  * cleanup required.  jpeg_mem_init will be called before anything is
196  * allocated (and, therefore, nothing in cinfo is of use except the error
197  * manager pointer).  It should return a suitable default value for
198  * max_memory_to_use; this may subsequently be overridden by the surrounding
199  * application.  (Note that max_memory_to_use is only important if
200  * jpeg_mem_available chooses to consult it ... no one else will.)
201  * jpeg_mem_term may assume that all requested memory has been freed and that
202  * all opened backing-store objects have been closed.
203  */
204
205 EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
206 EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));