29#define AM_MEMORY_MANAGER
74#define ALIGN_TYPE double
198 pool_id, (
long)
mem->total_space_allocated);
200 for (lhdr_ptr =
mem->large_list[pool_id]; lhdr_ptr !=
NULL;
201 lhdr_ptr = lhdr_ptr->hdr.
next) {
203 (
long) lhdr_ptr->hdr.bytes_used);
206 for (shdr_ptr =
mem->small_list[pool_id]; shdr_ptr !=
NULL;
207 shdr_ptr = shdr_ptr->hdr.
next) {
209 (
long) shdr_ptr->hdr.bytes_used,
210 (
long) shdr_ptr->hdr.bytes_left);
223 cinfo->err->trace_level = 2;
263 size_t odd_bytes, min_request, slop;
277 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
279 hdr_ptr =
mem->small_list[pool_id];
280 while (hdr_ptr !=
NULL) {
283 prev_hdr_ptr = hdr_ptr;
284 hdr_ptr = hdr_ptr->
hdr.next;
288 if (hdr_ptr ==
NULL) {
291 if (prev_hdr_ptr ==
NULL)
307 mem->total_space_allocated += min_request + slop;
310 hdr_ptr->
hdr.bytes_used = 0;
312 if (prev_hdr_ptr ==
NULL)
313 mem->small_list[pool_id] = hdr_ptr;
315 prev_hdr_ptr->
hdr.next = hdr_ptr;
319 data_ptr = (
char *) (hdr_ptr + 1);
320 data_ptr += hdr_ptr->
hdr.bytes_used;
324 return (
void *) data_ptr;
361 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
370 hdr_ptr->hdr.next =
mem->large_list[pool_id];
375 hdr_ptr->hdr.bytes_left = 0;
376 mem->large_list[pool_id] = hdr_ptr;
378 return (
void FAR *) (hdr_ptr + 1);
410 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
411 if (ltemp < (
long) numrows)
414 rowsperchunk = numrows;
415 mem->last_rowsperchunk = rowsperchunk;
423 while (currow < numrows) {
424 rowsperchunk =
MIN(rowsperchunk, numrows - currow);
427 for (
i = rowsperchunk;
i > 0;
i--) {
428 result[currow++] = workspace;
429 workspace += samplesperrow;
457 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
458 if (ltemp < (
long) numrows)
461 rowsperchunk = numrows;
462 mem->last_rowsperchunk = rowsperchunk;
470 while (currow < numrows) {
471 rowsperchunk =
MIN(rowsperchunk, numrows - currow);
474 for (
i = rowsperchunk;
i > 0;
i--) {
475 result[currow++] = workspace;
476 workspace += blocksperrow;
532 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
539 result->rows_in_array = numrows;
540 result->samplesperrow = samplesperrow;
541 result->maxaccess = maxaccess;
542 result->pre_zero = pre_zero;
562 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
569 result->rows_in_array = numrows;
570 result->blocksperrow = blocksperrow;
571 result->maxaccess = maxaccess;
572 result->pre_zero = pre_zero;
586 long bytesperrow, space_per_minheight, maximum_space;
587 long avail_mem, minheights, max_minheights;
595 space_per_minheight = 0;
597 for (sptr =
mem->virt_sarray_list; sptr !=
NULL; sptr = sptr->
next) {
598 if (sptr->mem_buffer ==
NULL) {
600 space_per_minheight += (
long) sptr->maxaccess * bytesperrow;
601 maximum_space += (
long) sptr->rows_in_array * bytesperrow;
604 for (bptr =
mem->virt_barray_list; bptr !=
NULL; bptr = bptr->
next) {
605 if (bptr->mem_buffer ==
NULL) {
607 space_per_minheight += (
long) bptr->maxaccess * bytesperrow;
608 maximum_space += (
long) bptr->rows_in_array * bytesperrow;
612 if (space_per_minheight <= 0)
617 (
long)
mem->total_space_allocated);
623 if (avail_mem >= maximum_space)
624 max_minheights = 1000000000L;
626 max_minheights = avail_mem / space_per_minheight;
630 if (max_minheights <= 0)
636 for (sptr =
mem->virt_sarray_list; sptr !=
NULL; sptr = sptr->
next) {
637 if (sptr->mem_buffer ==
NULL) {
638 minheights = ((
long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
639 if (minheights <= max_minheights) {
641 sptr->rows_in_mem = sptr->rows_in_array;
644 sptr->rows_in_mem = (
JDIMENSION) (max_minheights * sptr->maxaccess);
646 (
long) sptr->rows_in_array *
647 (
long) sptr->samplesperrow *
649 sptr->b_s_open =
TRUE;
652 sptr->samplesperrow, sptr->rows_in_mem);
653 sptr->rowsperchunk =
mem->last_rowsperchunk;
654 sptr->cur_start_row = 0;
655 sptr->first_undef_row = 0;
660 for (bptr =
mem->virt_barray_list; bptr !=
NULL; bptr = bptr->
next) {
661 if (bptr->mem_buffer ==
NULL) {
662 minheights = ((
long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
663 if (minheights <= max_minheights) {
665 bptr->rows_in_mem = bptr->rows_in_array;
668 bptr->rows_in_mem = (
JDIMENSION) (max_minheights * bptr->maxaccess);
670 (
long) bptr->rows_in_array *
671 (
long) bptr->blocksperrow *
673 bptr->b_s_open =
TRUE;
676 bptr->blocksperrow, bptr->rows_in_mem);
677 bptr->rowsperchunk =
mem->last_rowsperchunk;
678 bptr->cur_start_row = 0;
679 bptr->first_undef_row = 0;
690 long bytesperrow, file_offset, byte_count, rows, thisrow,
i;
693 file_offset = (
long)
ptr->cur_start_row * bytesperrow;
697 rows =
MIN((
long)
ptr->rowsperchunk, (
long)
ptr->rows_in_mem -
i);
699 thisrow = (
long)
ptr->cur_start_row +
i;
700 rows =
MIN(rows, (
long)
ptr->first_undef_row - thisrow);
702 rows =
MIN(rows, (
long)
ptr->rows_in_array - thisrow);
705 byte_count = rows * bytesperrow;
707 (*
ptr->b_s_info.write_backing_store) (cinfo, &
ptr->b_s_info,
708 (
void FAR *)
ptr->mem_buffer[
i],
709 file_offset, byte_count);
711 (*
ptr->b_s_info.read_backing_store) (cinfo, &
ptr->b_s_info,
712 (
void FAR *)
ptr->mem_buffer[
i],
713 file_offset, byte_count);
714 file_offset += byte_count;
723 long bytesperrow, file_offset, byte_count, rows, thisrow,
i;
726 file_offset = (
long)
ptr->cur_start_row * bytesperrow;
730 rows =
MIN((
long)
ptr->rowsperchunk, (
long)
ptr->rows_in_mem -
i);
732 thisrow = (
long)
ptr->cur_start_row +
i;
733 rows =
MIN(rows, (
long)
ptr->first_undef_row - thisrow);
735 rows =
MIN(rows, (
long)
ptr->rows_in_array - thisrow);
738 byte_count = rows * bytesperrow;
740 (*
ptr->b_s_info.write_backing_store) (cinfo, &
ptr->b_s_info,
741 (
void FAR *)
ptr->mem_buffer[
i],
742 file_offset, byte_count);
744 (*
ptr->b_s_info.read_backing_store) (cinfo, &
ptr->b_s_info,
745 (
void FAR *)
ptr->mem_buffer[
i],
746 file_offset, byte_count);
747 file_offset += byte_count;
766 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
769 if (start_row < ptr->cur_start_row ||
770 end_row >
ptr->cur_start_row +
ptr->rows_in_mem) {
772 ERREXIT(cinfo, JERR_VIRTUAL_BUG);
785 if (start_row >
ptr->cur_start_row) {
786 ptr->cur_start_row = start_row;
791 ltemp = (
long) end_row - (
long)
ptr->rows_in_mem;
806 if (
ptr->first_undef_row < end_row) {
807 if (
ptr->first_undef_row < start_row) {
809 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
810 undef_row = start_row;
812 undef_row =
ptr->first_undef_row;
815 ptr->first_undef_row = end_row;
818 undef_row -=
ptr->cur_start_row;
819 end_row -=
ptr->cur_start_row;
820 while (undef_row < end_row) {
826 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
833 return ptr->mem_buffer + (start_row -
ptr->cur_start_row);
851 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
854 if (start_row < ptr->cur_start_row ||
855 end_row >
ptr->cur_start_row +
ptr->rows_in_mem) {
857 ERREXIT(cinfo, JERR_VIRTUAL_BUG);
870 if (start_row >
ptr->cur_start_row) {
871 ptr->cur_start_row = start_row;
876 ltemp = (
long) end_row - (
long)
ptr->rows_in_mem;
891 if (
ptr->first_undef_row < end_row) {
892 if (
ptr->first_undef_row < start_row) {
894 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
895 undef_row = start_row;
897 undef_row =
ptr->first_undef_row;
900 ptr->first_undef_row = end_row;
903 undef_row -=
ptr->cur_start_row;
904 end_row -=
ptr->cur_start_row;
905 while (undef_row < end_row) {
911 ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
918 return ptr->mem_buffer + (start_row -
ptr->cur_start_row);
935 ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);
938 if (cinfo->err->trace_level > 1)
939 print_mem_stats(cinfo, pool_id);
947 for (sptr =
mem->virt_sarray_list; sptr !=
NULL; sptr = sptr->
next) {
954 for (bptr =
mem->virt_barray_list; bptr !=
NULL; bptr = bptr->
next) {
964 lhdr_ptr =
mem->large_list[pool_id];
965 mem->large_list[pool_id] =
NULL;
967 while (lhdr_ptr !=
NULL) {
969 space_freed = lhdr_ptr->hdr.bytes_used +
970 lhdr_ptr->hdr.bytes_left +
973 mem->total_space_allocated -= space_freed;
974 lhdr_ptr = next_lhdr_ptr;
978 shdr_ptr =
mem->small_list[pool_id];
979 mem->small_list[pool_id] =
NULL;
981 while (shdr_ptr !=
NULL) {
983 space_freed = shdr_ptr->hdr.bytes_used +
984 shdr_ptr->hdr.bytes_left +
987 mem->total_space_allocated -= space_freed;
988 shdr_ptr = next_shdr_ptr;
1042 ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
1051 ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
1060 ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
1080 mem->pub.max_memory_to_use = max_to_use;
1092 cinfo->mem = &
mem->pub;
1106 if (
sscanf(memenv,
"%ld%c", &max_to_use, &ch) > 0) {
1107 if (ch ==
'm' || ch ==
'M')
1108 max_to_use *= 1000L;
1109 mem->pub.max_memory_to_use = max_to_use * 1000L;
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
#define ERREXIT1(cinfo, code, p1)
jpeg_free_large(j_common_ptr cinfo, void FAR *object, size_t sizeofobject)
jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject)
jpeg_free_small(j_common_ptr cinfo, void *object, size_t sizeofobject)
jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject)
jpeg_mem_term(j_common_ptr cinfo)
jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
jpeg_mem_available(j_common_ptr cinfo, long min_bytes_needed, long max_bytes_needed, long already_allocated)
jpeg_mem_init(j_common_ptr cinfo)
union large_pool_struct FAR * large_pool_ptr
self_destruct(j_common_ptr cinfo)
alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows)
request_virt_sarray(j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION samplesperrow, JDIMENSION numrows, JDIMENSION maxaccess)
access_virt_barray(j_common_ptr cinfo, jvirt_barray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
union small_pool_struct * small_pool_ptr
union large_pool_struct large_pool_hdr
request_virt_barray(j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION blocksperrow, JDIMENSION numrows, JDIMENSION maxaccess)
access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
union small_pool_struct small_pool_hdr
alloc_small(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
my_memory_mgr * my_mem_ptr
static const size_t extra_pool_slop[JPOOL_NUMPOOLS]
do_barray_io(j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
jinit_memory_mgr(j_common_ptr cinfo)
free_pool(j_common_ptr cinfo, int pool_id)
out_of_memory(j_common_ptr cinfo, int which)
realize_virt_arrays(j_common_ptr cinfo)
static const size_t first_pool_slop[JPOOL_NUMPOOLS]
do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
alloc_large(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
alloc_barray(j_common_ptr cinfo, int pool_id, JDIMENSION blocksperrow, JDIMENSION numrows)
#define FMEMZERO(target, size)
int JSAMPARRAY int int num_rows
struct jvirt_barray_control * jvirt_barray_ptr
struct jvirt_sarray_control * jvirt_sarray_ptr
static void test_mac(void)
backing_store_info b_s_info
JDIMENSION first_undef_row
JDIMENSION first_undef_row
backing_store_info b_s_info
jvirt_barray_ptr virt_barray_list
size_t total_space_allocated
JDIMENSION last_rowsperchunk
jvirt_sarray_ptr virt_sarray_list
struct large_pool_struct::@182 hdr
struct small_pool_struct::@181 hdr