2 { Delphi3 -- > jmemnobs from jmemwin }
3 { This file provides an Win32-compatible implementation of the system-
4 dependent portion of the JPEG memory manager. }
6 { Check jmemnobs.c }
7 { Copyright (C) 1996, Jacques Nomssi Nzali }
10 interface
12 {$I imjconfig.inc}
14 uses
15 imjmorecfg,
16 imjdeferr,
17 imjerror,
18 imjpeglib;
20 { The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
21 be requested in a single call to jpeg_get_large (and jpeg_get_small for that
22 matter, but that case should never come into play). This macro is needed
23 to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
24 On those machines, we expect that jconfig.h will provide a proper value.
25 On machines with 32-bit flat address spaces, any large constant may be used.
27 NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
28 size_t and will be a multiple of sizeof(align_type). }
30 const
33 {GLOBAL}
38 { These routines take care of any system-dependent initialization and
39 cleanup required. }
41 {GLOBAL}
44 {GLOBAL}
47 { These two functions are used to allocate and release small chunks of
48 memory. (Typically the total amount requested through jpeg_get_small is
49 no more than 20K or so; this will be requested in chunks of a few K each.)
50 Behavior should be the same as for the standard library functions malloc
51 and free; in particular, jpeg_get_small must return NIL on failure.
52 On most systems, these ARE malloc and free. jpeg_free_small is passed the
53 size of the object being freed, just in case it's needed.
54 On an 80x86 machine using small-data memory model, these manage near heap. }
57 { Near-memory allocation and freeing are controlled by the regular library
58 routines malloc() and free(). }
60 {GLOBAL}
64 {GLOBAL}
65 {object is a reserved word in Borland Pascal }
70 { These two functions are used to allocate and release large chunks of
71 memory (up to the total free space designated by jpeg_mem_available).
72 The interface is the same as above, except that on an 80x86 machine,
73 far pointers are used. On most other machines these are identical to
74 the jpeg_get/free_small routines; but we keep them separate anyway,
75 in case a different allocation strategy is desirable for large chunks. }
78 { "Large" objects are allocated in far memory, if possible }
81 {GLOBAL}
85 {GLOBAL}
90 { This routine computes the total memory space available for allocation.
91 It's impossible to do this in a portable way; our current solution is
92 to make the user tell us (with a default value set at compile time).
93 If you can actually get the available space, it's a good idea to subtract
94 a slop factor of 5% or so. }
96 {GLOBAL}
103 implementation
105 { This structure holds whatever state is needed to access a single
106 backing-store object. The read/write/close method pointers are called
107 by jmemmgr.c to manipulate the backing-store object; all other fields
108 are private to the system-dependent backing store routines. }
112 { These two functions are used to allocate and release small chunks of
113 memory. (Typically the total amount requested through jpeg_get_small is
114 no more than 20K or so; this will be requested in chunks of a few K each.)
115 Behavior should be the same as for the standard library functions malloc
116 and free; in particular, jpeg_get_small must return NIL on failure.
117 On most systems, these ARE malloc and free. jpeg_free_small is passed the
118 size of the object being freed, just in case it's needed.
119 On an 80x86 machine using small-data memory model, these manage near heap. }
122 { Near-memory allocation and freeing are controlled by the regular library
123 routines malloc() and free(). }
125 {GLOBAL}
128 var
130 begin
135 {GLOBAL}
136 {object is a reserved word in Object Pascal }
140 begin
144 { These two functions are used to allocate and release large chunks of
145 memory (up to the total free space designated by jpeg_mem_available).
146 The interface is the same as above, except that on an 80x86 machine,
147 far pointers are used. On most other machines these are identical to
148 the jpeg_get/free_small routines; but we keep them separate anyway,
149 in case a different allocation strategy is desirable for large chunks. }
153 {GLOBAL}
156 var
158 begin
163 {GLOBAL}
167 begin
171 { This routine computes the total space still available for allocation by
172 jpeg_get_large. If more space than this is needed, backing store will be
173 used. NOTE: any memory already allocated must not be counted.
175 There is a minimum space requirement, corresponding to the minimum
176 feasible buffer sizes; jmemmgr.c will request that much space even if
177 jpeg_mem_available returns zero. The maximum space needed, enough to hold
178 all working storage in memory, is also passed in case it is useful.
179 Finally, the total space already allocated is passed. If no better
180 method is available, cinfo^.mem^.max_memory_to_use - already_allocated
181 is often a suitable calculation.
183 It is OK for jpeg_mem_available to underestimate the space available
184 (that'll just lead to more backing-store access than is really necessary).
185 However, an overestimate will lead to failure. Hence it's wise to subtract
186 a slop factor from the true available space. 5% should be enough.
188 On machines with lots of virtual memory, any large constant may be returned.
189 Conversely, zero may be returned to always use the minimum amount of memory.}
193 { This routine computes the total memory space available for allocation.
194 It's impossible to do this in a portable way; our current solution is
195 to make the user tell us (with a default value set at compile time).
196 If you can actually get the available space, it's a good idea to subtract
197 a slop factor of 5% or so. }
199 const
202 {GLOBAL}
207 begin
208 {jpeg_mem_available := cinfo^.mem^.max_memory_to_use - already_allocated;}
213 { Initial opening of a backing-store object. This must fill in the
214 read/write/close pointers in the object. The read/write routines
215 may take an error exit if the specified maximum file size is exceeded.
216 (If jpeg_mem_available always returns a large value, this routine can
217 just take an error exit.) }
221 { Initial opening of a backing-store object. }
223 {GLOBAL}
227 begin
231 { These routines take care of any system-dependent initialization and
232 cleanup required. jpeg_mem_init will be called before anything is
233 allocated (and, therefore, nothing in cinfo is of use except the error
234 manager pointer). It should return a suitable default value for
235 max_memory_to_use; this may subsequently be overridden by the surrounding
236 application. (Note that max_memory_to_use is only important if
237 jpeg_mem_available chooses to consult it ... no one else will.)
238 jpeg_mem_term may assume that all requested memory has been freed and that
239 all opened backing-store objects have been closed. }
242 { These routines take care of any system-dependent initialization and
243 cleanup required. }
246 {GLOBAL}
248 begin
252 {GLOBAL}
254 begin