Main GraphicsMagick source repository
Revisión | cedbb6f8bc14497c21ac373b585d8c51434e48cd (tree) |
---|---|
Tiempo | 2021-06-06 00:30:40 |
Autor | Bob Friesenhahn <bfriesen@Grap...> |
Commiter | Bob Friesenhahn |
Managed-memory: Round up allocation size on small reallocs in order to lessen the number of actual reallocs.
@@ -1,3 +1,9 @@ | ||
1 | +2021-06-05 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> | |
2 | + | |
3 | + * magick/memory.c (_MagickReallocateResourceLimitedMemory): Round | |
4 | + up allocation size on small reallocs in order to lessen the number | |
5 | + of actual reallocs. | |
6 | + | |
1 | 7 | 2021-05-31 Bob Friesenhahn <bfriesen@simple.dallas.tx.us> |
2 | 8 | |
3 | 9 | * coders/svg.c (SVGComment): Re-implement comment callback to be based on |
@@ -10,5 +10,5 @@ | ||
10 | 10 | |
11 | 11 | #define public MagickPackageName "GraphicsMagick" |
12 | 12 | #define public MagickPackageVersion "1.4" |
13 | -#define public MagickPackageVersionAddendum ".020210531" | |
14 | -#define public MagickPackageReleaseDate "snapshot-20210531" | |
13 | +#define public MagickPackageVersionAddendum ".020210605" | |
14 | +#define public MagickPackageReleaseDate "snapshot-20210605" |
@@ -729,9 +729,19 @@ | ||
729 | 729 | if (new_size > memory_resource.alloc_size_real) |
730 | 730 | { |
731 | 731 | void *realloc_memory; |
732 | - /* FIXME: Maybe over-allocate here if re-alloc? */ | |
732 | + size_t realloc_size = new_size+sizeof(MagickMemoryResource_T); | |
733 | + /* | |
734 | + If this is a realloc, then round up underlying | |
735 | + allocation sizes for small allocations in order to | |
736 | + lessen realloc calls and lessen memory moves. | |
737 | + */ | |
738 | + if ((memory_resource.alloc_size_real != 0) && (realloc_size < 131072)) | |
739 | + { | |
740 | + /* realloc_size <<= 1; */ | |
741 | + MagickRoundUpStringLength(realloc_size); | |
742 | + } | |
733 | 743 | realloc_memory = (ReallocFunc)(memory_resource.memory, |
734 | - new_size+sizeof(MagickMemoryResource_T)); | |
744 | + realloc_size); | |
735 | 745 | if (realloc_memory != 0) |
736 | 746 | { |
737 | 747 | if (clear) |
@@ -745,7 +755,7 @@ | ||
745 | 755 | memory_resource.num_realloc_moves++; |
746 | 756 | memory_resource.memory = realloc_memory; |
747 | 757 | memory_resource.alloc_size = new_size; |
748 | - memory_resource.alloc_size_real = new_size; | |
758 | + memory_resource.alloc_size_real = realloc_size-sizeof(MagickMemoryResource_T); | |
749 | 759 | } |
750 | 760 | else |
751 | 761 | { |
@@ -39,21 +39,23 @@ | ||
39 | 39 | |
40 | 40 | /* |
41 | 41 | Compute a value which is the next kilobyte power of 2 larger than |
42 | - the requested value or MaxTextExtent, whichever is larger. | |
42 | + the requested value or 256 whichever is larger. | |
43 | 43 | |
44 | 44 | The objective is to round up the size quickly (and in repeatable |
45 | 45 | steps) in order to reduce the number of memory copies due to realloc |
46 | 46 | for strings which grow rapidly, while producing a reasonable size |
47 | 47 | for smaller strings. |
48 | 48 | */ |
49 | -#define MagickRoundUpStringLength(size) \ | |
50 | -{ \ | |
51 | - size_t \ | |
52 | - _rounded; \ | |
53 | - \ | |
54 | - for (_rounded=256U; _rounded < (Max(size,256)); _rounded *= 2); \ | |
55 | - size=_rounded; \ | |
56 | -} | |
49 | +#define MagickRoundUpStringLength(size) \ | |
50 | + do { \ | |
51 | + size_t \ | |
52 | + _rounded, \ | |
53 | + _target; \ | |
54 | + \ | |
55 | + _target=(Max(size,256)); \ | |
56 | + for (_rounded=256U; _rounded < _target; _rounded *= 2); \ | |
57 | + size=_rounded; \ | |
58 | +} while(0) | |
57 | 59 | |
58 | 60 | /* |
59 | 61 | * Local Variables: |
@@ -38,8 +38,8 @@ | ||
38 | 38 | #define MagickLibVersion 0x252200 |
39 | 39 | #define MagickLibVersionText "1.4" |
40 | 40 | #define MagickLibVersionNumber 25,22,0 |
41 | -#define MagickChangeDate "20210531" | |
42 | -#define MagickReleaseDate "snapshot-20210531" | |
41 | +#define MagickChangeDate "20210605" | |
42 | +#define MagickReleaseDate "snapshot-20210605" | |
43 | 43 | |
44 | 44 | /* |
45 | 45 | The MagickLibInterfaceNewest and MagickLibInterfaceOldest defines |
@@ -35,6 +35,11 @@ | ||
35 | 35 | <div class="document"> |
36 | 36 | |
37 | 37 | |
38 | +<p>2021-06-05 Bob Friesenhahn <<a class="reference external" href="mailto:bfriesen%40simple.dallas.tx.us">bfriesen<span>@</span>simple<span>.</span>dallas<span>.</span>tx<span>.</span>us</a>></p> | |
39 | +<blockquote> | |
40 | +* magick/memory.c (_MagickReallocateResourceLimitedMemory): Round | |
41 | +up allocation size on small reallocs in order to lessen the number | |
42 | +of actual reallocs.</blockquote> | |
38 | 43 | <p>2021-05-31 Bob Friesenhahn <<a class="reference external" href="mailto:bfriesen%40simple.dallas.tx.us">bfriesen<span>@</span>simple<span>.</span>dallas<span>.</span>tx<span>.</span>us</a>></p> |
39 | 44 | <blockquote> |
40 | 45 | <p>* coders/svg.c (SVGComment): Re-implement comment callback to be based on |
@@ -3,7 +3,7 @@ | ||
3 | 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
4 | 4 | <head> |
5 | 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
6 | -<meta name="generator" content="Docutils 0.16: http://docutils.sourceforge.net/" /> | |
6 | +<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" /> | |
7 | 7 | <title>memory</title> |
8 | 8 | <link rel="stylesheet" href="../docutils-api.css" type="text/css" /> |
9 | 9 | </head> |
@@ -37,7 +37,7 @@ | ||
37 | 37 | <h2 class="subtitle" id="memory-allocation-deallocation-functions">Memory allocation/deallocation functions</h2> |
38 | 38 | |
39 | 39 | <div class="contents topic" id="contents"> |
40 | -<p class="topic-title">Contents</p> | |
40 | +<p class="topic-title first">Contents</p> | |
41 | 41 | <ul class="simple"> |
42 | 42 | <li><a class="reference internal" href="#magickallocfunctions" id="id15">MagickAllocFunctions</a></li> |
43 | 43 | <li><a class="reference internal" href="#magickmalloc" id="id16">MagickMalloc</a></li> |