1 | /*
|
---|
2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
3 | % %
|
---|
4 | % %
|
---|
5 | % %
|
---|
6 | % M M EEEEE M M OOO RRRR Y Y %
|
---|
7 | % MM MM E MM MM O O R R Y Y %
|
---|
8 | % M M M EEE M M M O O RRRR Y %
|
---|
9 | % M M E M M O O R R Y %
|
---|
10 | % M M EEEEE M M OOO R R Y %
|
---|
11 | % %
|
---|
12 | % %
|
---|
13 | % ImageMagick Memory Allocation Methods %
|
---|
14 | % %
|
---|
15 | % %
|
---|
16 | % Software Design %
|
---|
17 | % John Cristy %
|
---|
18 | % July 1998 %
|
---|
19 | % %
|
---|
20 | % %
|
---|
21 | % Copyright 1999 E. I. du Pont de Nemours and Company %
|
---|
22 | % %
|
---|
23 | % Permission is hereby granted, free of charge, to any person obtaining a %
|
---|
24 | % copy of this software and associated documentation files ("ImageMagick"), %
|
---|
25 | % to deal in ImageMagick without restriction, including without limitation %
|
---|
26 | % the rights to use, copy, modify, merge, publish, distribute, sublicense, %
|
---|
27 | % and/or sell copies of ImageMagick, and to permit persons to whom the %
|
---|
28 | % ImageMagick is furnished to do so, subject to the following conditions: %
|
---|
29 | % %
|
---|
30 | % The above copyright notice and this permission notice shall be included in %
|
---|
31 | % all copies or substantial portions of ImageMagick. %
|
---|
32 | % %
|
---|
33 | % The software is provided "as is", without warranty of any kind, express or %
|
---|
34 | % implied, including but not limited to the warranties of merchantability, %
|
---|
35 | % fitness for a particular purpose and noninfringement. In no event shall %
|
---|
36 | % E. I. du Pont de Nemours and Company be liable for any claim, damages or %
|
---|
37 | % other liability, whether in an action of contract, tort or otherwise, %
|
---|
38 | % arising from, out of or in connection with ImageMagick or the use or other %
|
---|
39 | % dealings in ImageMagick. %
|
---|
40 | % %
|
---|
41 | % Except as contained in this notice, the name of the E. I. du Pont de %
|
---|
42 | % Nemours and Company shall not be used in advertising or otherwise to %
|
---|
43 | % promote the sale, use or other dealings in ImageMagick without prior %
|
---|
44 | % written authorization from the E. I. du Pont de Nemours and Company. %
|
---|
45 | % %
|
---|
46 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
47 | %
|
---|
48 | %
|
---|
49 | %
|
---|
50 | */
|
---|
51 | |
---|
52 |
|
---|
53 | /*
|
---|
54 | Include declarations.
|
---|
55 | */
|
---|
56 | #include "magick.h"
|
---|
57 | #include "defines.h"
|
---|
58 | |
---|
59 |
|
---|
60 | /*
|
---|
61 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
62 | % %
|
---|
63 | % %
|
---|
64 | % %
|
---|
65 | % F r e e M e m o r y %
|
---|
66 | % %
|
---|
67 | % %
|
---|
68 | % %
|
---|
69 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
70 | %
|
---|
71 | % Method FreeMemory frees memory that has already been allocated.
|
---|
72 | %
|
---|
73 | % The format of the FreeMemory method is:
|
---|
74 | %
|
---|
75 | % void FreeMemory(void *memory)
|
---|
76 | %
|
---|
77 | % A description of each parameter follows:
|
---|
78 | %
|
---|
79 | % o span: Specifies the pointer to a block memory to free for reuse.
|
---|
80 | %
|
---|
81 | %
|
---|
82 | */
|
---|
83 | Export void FreeMemory(void *memory)
|
---|
84 | {
|
---|
85 | if (memory == (void *) NULL)
|
---|
86 | return;
|
---|
87 | free(memory);
|
---|
88 | memory=(void *)NULL;
|
---|
89 | }
|
---|
90 |
|
---|
91 | Export void *AllocateMemory(const size_t size)
|
---|
92 | {
|
---|
93 | return(malloc(size));
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | /*
|
---|
98 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
99 | % %
|
---|
100 | % %
|
---|
101 | % %
|
---|
102 | % R e a l l o c a t e M e m o r y %
|
---|
103 | % %
|
---|
104 | % %
|
---|
105 | % %
|
---|
106 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
107 | %
|
---|
108 | % Method ReallocateMemory changes the size of the memory and returns a
|
---|
109 | % pointer to the (possibly moved) block. The contents will be unchanged up
|
---|
110 | % to the lesser of the new and old sizes.
|
---|
111 | %
|
---|
112 | % The format of the ReallocateMemory method is:
|
---|
113 | %
|
---|
114 | % void *ReallocateMemory(void *memory,const size_t size)
|
---|
115 | %
|
---|
116 | % A description of each parameter follows:
|
---|
117 | %
|
---|
118 | % o memory: Method ReallocateMemory returns a pointer to a block of at
|
---|
119 | % least size bytes suitably aligned for any use.
|
---|
120 | %
|
---|
121 | % o size: Specifies the size of the memory to return.
|
---|
122 | %
|
---|
123 | %
|
---|
124 | */
|
---|
125 | Export void *ReallocateMemory(void *memory,const size_t size)
|
---|
126 | {
|
---|
127 | void
|
---|
128 | *new_memory;
|
---|
129 |
|
---|
130 | new_memory=(void *) NULL;
|
---|
131 | if (size)
|
---|
132 | new_memory=realloc(memory,size);
|
---|
133 | if (new_memory == (void *) NULL)
|
---|
134 | FreeMemory(memory);
|
---|
135 | return(new_memory);
|
---|
136 | }
|
---|
137 |
|
---|