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



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020