Main MRPT website > C++ reference for MRPT 1.9.9
jmemsys.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 /* Short forms of external names for systems with brain-damaged linkers. */
11 
12 #ifdef NEED_SHORT_EXTERNAL_NAMES
13 #define jpeg_get_small jGetSmall
14 #define jpeg_free_small jFreeSmall
15 #define jpeg_get_large jGetLarge
16 #define jpeg_free_large jFreeLarge
17 #define jpeg_mem_available jMemAvail
18 #define jpeg_open_backing_store jOpenBackStore
19 #define jpeg_mem_init jMemInit
20 #define jpeg_mem_term jMemTerm
21 #endif /* NEED_SHORT_EXTERNAL_NAMES */
22 
23 /*
24  * These two functions are used to allocate and release small chunks of
25  * memory. (Typically the total amount requested through jpeg_get_small is
26  * no more than 20K or so; this will be requested in chunks of a few K each.)
27  * Behavior should be the same as for the standard library functions malloc
28  * and free; in particular, jpeg_get_small must return nullptr on failure.
29  * On most systems, these ARE malloc and free. jpeg_free_small is passed the
30  * size of the object being freed, just in case it's needed.
31  * On an 80x86 machine using small-data memory model, these manage near heap.
32  */
33 
35 EXTERN(void)
36 jpeg_free_small JPP((j_common_ptr cinfo, void* object, size_t sizeofobject));
37 
38 /*
39  * These two functions are used to allocate and release large chunks of
40  * memory (up to the total free space designated by jpeg_mem_available).
41  * The interface is the same as above, except that on an 80x86 machine,
42  * far pointers are used. On most other machines these are identical to
43  * the jpeg_get/free_small routines; but we keep them separate anyway,
44  * in case a different allocation strategy is desirable for large chunks.
45  */
46 
47 EXTERN(void FAR*) jpeg_get_large JPP((j_common_ptr cinfo, size_t sizeofobject));
48 EXTERN(void)
50  (j_common_ptr cinfo, void FAR* object, size_t sizeofobject));
51 
52 /*
53  * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
54  * be requested in a single call to jpeg_get_large (and jpeg_get_small for that
55  * matter, but that case should never come into play). This macro is needed
56  * to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
57  * On those machines, we expect that mrpt_jconfig.h will provide a proper value.
58  * On machines with 32-bit flat address spaces, any large constant may be used.
59  *
60  * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
61  * size_t and will be a multiple of sizeof(align_type).
62  */
63 
64 #ifndef MAX_ALLOC_CHUNK /* may be overridden in mrpt_jconfig.h */
65 #define MAX_ALLOC_CHUNK 1000000000L
66 #endif
67 
68 /*
69  * This routine computes the total space still available for allocation by
70  * jpeg_get_large. If more space than this is needed, backing store will be
71  * used. NOTE: any memory already allocated must not be counted.
72  *
73  * There is a minimum space requirement, corresponding to the minimum
74  * feasible buffer sizes; jmemmgr.c will request that much space even if
75  * jpeg_mem_available returns zero. The maximum space needed, enough to hold
76  * all working storage in memory, is also passed in case it is useful.
77  * Finally, the total space already allocated is passed. If no better
78  * method is available, cinfo->mem->max_memory_to_use - already_allocated
79  * is often a suitable calculation.
80  *
81  * It is OK for jpeg_mem_available to underestimate the space available
82  * (that'll just lead to more backing-store access than is really necessary).
83  * However, an overestimate will lead to failure. Hence it's wise to subtract
84  * a slop factor from the true available space. 5% should be enough.
85  *
86  * On machines with lots of virtual memory, any large constant may be returned.
87  * Conversely, zero may be returned to always use the minimum amount of memory.
88  */
89 
90 EXTERN(long)
92  (j_common_ptr cinfo, long min_bytes_needed, long max_bytes_needed,
93  long already_allocated));
94 
95 /*
96  * This structure holds whatever state is needed to access a single
97  * backing-store object. The read/write/close method pointers are called
98  * by jmemmgr.c to manipulate the backing-store object; all other fields
99  * are private to the system-dependent backing store routines.
100  */
101 
102 #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
103 
104 #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
105 
106 typedef unsigned short XMSH; /* type of extended-memory handles */
107 typedef unsigned short EMSH; /* type of expanded-memory handles */
108 
109 typedef union {
110  short file_handle; /* DOS file handle if it's a temp file */
111  XMSH xms_handle; /* handle if it's a chunk of XMS */
112  EMSH ems_handle; /* handle if it's a chunk of EMS */
113 } handle_union;
114 
115 #endif /* USE_MSDOS_MEMMGR */
116 
117 #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
118 #include <Files.h>
119 #endif /* USE_MAC_MEMMGR */
120 
122 
123 typedef struct backing_store_struct
124 {
125  /* Methods for reading/writing/closing this backing-store object */
126  JMETHOD(
127  void, read_backing_store,
128  (j_common_ptr cinfo, backing_store_ptr info, void FAR* buffer_address,
129  long file_offset, long byte_count));
130  JMETHOD(
131  void, write_backing_store,
132  (j_common_ptr cinfo, backing_store_ptr info, void FAR* buffer_address,
133  long file_offset, long byte_count));
134  JMETHOD(
135  void, close_backing_store,
136  (j_common_ptr cinfo, backing_store_ptr info));
137 
138 /* Private fields for system-dependent backing-store management */
139 #ifdef USE_MSDOS_MEMMGR
140  /* For the MS-DOS manager (jmemdos.c), we need: */
141  handle_union handle; /* reference to backing-store storage object */
142  char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
143 #else
144 #ifdef USE_MAC_MEMMGR
145  /* For the Mac manager (jmemmac.c), we need: */
146  short temp_file; /* file reference number to temp file */
147  FSSpec tempSpec; /* the FSSpec for the temp file */
148  char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
149 #else
150  /* For a typical implementation with temp files, we need: */
151  FILE* temp_file; /* stdio reference to temp file */
152  char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
153 #endif
154 #endif
156 
157 /*
158  * Initial opening of a backing-store object. This must fill in the
159  * read/write/close pointers in the object. The read/write routines
160  * may take an error exit if the specified maximum file size is exceeded.
161  * (If jpeg_mem_available always returns a large value, this routine can
162  * just take an error exit.)
163  */
164 
165 EXTERN(void)
167  (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed));
168 
169 /*
170  * These routines take care of any system-dependent initialization and
171  * cleanup required. jpeg_mem_init will be called before anything is
172  * allocated (and, therefore, nothing in cinfo is of use except the error
173  * manager pointer). It should return a suitable default value for
174  * max_memory_to_use; this may subsequently be overridden by the surrounding
175  * application. (Note that max_memory_to_use is only important if
176  * jpeg_mem_available chooses to consult it ... no one else will.)
177  * jpeg_mem_term may assume that all requested memory has been freed and that
178  * all opened backing-store objects have been closed.
179  */
180 
181 EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
182 EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
jpeg_mem_init(j_common_ptr)
Definition: jmemnobs.cpp:77
jpeg_get_small(j_common_ptr, size_t sizeofobject)
Definition: jmemnobs.cpp:26
JMETHOD(void, read_backing_store,(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count))
struct backing_store_struct * backing_store_ptr
Definition: jmemsys.h:121
char temp_name[TEMP_NAME_LENGTH]
Definition: jmemsys.h:152
EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo
jpeg_free_small(j_common_ptr, void *object, size_t)
Definition: jmemnobs.cpp:32
struct backing_store_struct backing_store_info
jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr, long)
Definition: jmemnobs.cpp:66
size_t sizeofobject
Definition: jmemsys.h:34
#define TEMP_NAME_LENGTH
Definition: jmemsys.h:102
jpeg_mem_available(j_common_ptr, long, long max_bytes_needed, long)
Definition: jmemnobs.cpp:54
jpeg_mem_term(j_common_ptr)
Definition: jmemnobs.cpp:79
jpeg_free_large(j_common_ptr, void FAR *object, size_t)
Definition: jmemnobs.cpp:47
jpeg_free_small JPP((j_common_ptr cinfo, void *object, size_t sizeofobject))
#define FAR
Definition: zconf.h:262
jpeg_get_large(j_common_ptr, size_t sizeofobject)
Definition: jmemnobs.cpp:41



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019