MagickCore 7.1.0
Convert, Edit, Or Compose Bitmap Images
memory.c File Reference
Include dependency graph for memory.c:

Go to the source code of this file.

Data Structures

struct  _DataSegmentInfo
 
struct  _MagickMemoryMethods
 
struct  _MemoryInfo
 
struct  _MemoryPool
 

Macros

#define BlockFooter(block, size)    ((size_t *) ((char *) (block)+(size)-2*sizeof(size_t)))
 
#define BlockHeader(block)   ((size_t *) (block)-1)
 
#define BlockThreshold   1024
 
#define MaxBlockExponent   16
 
#define MaxBlocks   ((BlockThreshold/(4*sizeof(size_t)))+MaxBlockExponent+1)
 
#define MaxSegments   1024
 
#define NextBlock(block)   ((char *) (block)+SizeOfBlock(block))
 
#define NextBlockInList(block)   (*(void **) (block))
 
#define PreviousBlock(block)   ((char *) (block)-(*((size_t *) (block)-2)))
 
#define PreviousBlockBit   0x01
 
#define PreviousBlockInList(block)   (*((void **) (block)+1))
 
#define SegmentSize   (2*1024*1024)
 
#define SizeMask   (~0x01)
 
#define SizeOfBlock(block)   (*BlockHeader(block) & SizeMask)
 
#define ALIGNMENT_OVERHEAD    (MAGICKCORE_MAX_ALIGNMENT_PADDING(CACHE_LINE_SIZE) + MAGICKCORE_SIZEOF_VOID_P)
 
#define AcquireAlignedMemory_Actual   AcquireAlignedMemory_Generic
 
#define MinMemoryRequest   "16MiB"
 

Typedefs

typedef struct _DataSegmentInfo DataSegmentInfo
 
typedef struct _MagickMemoryMethods MagickMemoryMethods
 
typedef struct _MemoryPool MemoryPool
 

Enumerations

enum  VirtualMemoryType { UndefinedVirtualMemory , AlignedVirtualMemory , MapVirtualMemory , UnalignedVirtualMemory }
 

Functions

static void * reserve_space_for_actual_base_address (void *const p)
 
static void ** pointer_to_space_for_actual_base_address (void *const p)
 
static void * actual_base_address (void *const p)
 
static void * align_to_cache (void *const p)
 
static void * adjust (void *const p)
 
static void * AcquireAlignedMemory_Generic (const size_t size)
 
MagickExport void * AcquireAlignedMemory (const size_t count, const size_t quantum)
 
MagickExport void * AcquireMagickMemory (const size_t size)
 
MagickExport void * AcquireCriticalMemory (const size_t size)
 
MagickExport void * AcquireQuantumMemory (const size_t count, const size_t quantum)
 
MagickExport MemoryInfoAcquireVirtualMemory (const size_t count, const size_t quantum)
 
MagickExport void * CopyMagickMemory (void *magick_restrict destination, const void *magick_restrict source, const size_t size)
 
MagickExport void DestroyMagickMemory (void)
 
MagickExport void GetMagickMemoryMethods (AcquireMemoryHandler *acquire_memory_handler, ResizeMemoryHandler *resize_memory_handler, DestroyMemoryHandler *destroy_memory_handler)
 
MagickExport size_t GetMaxMemoryRequest (void)
 
MagickExport void * GetVirtualMemoryBlob (const MemoryInfo *memory_info)
 
MagickExport void * RelinquishAlignedMemory (void *memory)
 
MagickExport void * RelinquishMagickMemory (void *memory)
 
MagickExport MemoryInfoRelinquishVirtualMemory (MemoryInfo *memory_info)
 
MagickExport void * ResetMagickMemory (void *memory, int c, const size_t size)
 
MagickPrivate void ResetMaxMemoryRequest (void)
 
MagickPrivate void ResetVirtualAnonymousMemory (void)
 
MagickExport void * ResizeMagickMemory (void *memory, const size_t size)
 
MagickExport void * ResizeQuantumMemory (void *memory, const size_t count, const size_t quantum)
 
MagickExport void SetMagickAlignedMemoryMethods (AcquireAlignedMemoryHandler acquire_aligned_memory_handler, RelinquishAlignedMemoryHandler relinquish_aligned_memory_handler)
 
MagickExport void SetMagickMemoryMethods (AcquireMemoryHandler acquire_memory_handler, ResizeMemoryHandler resize_memory_handler, DestroyMemoryHandler destroy_memory_handler)
 

Variables

static size_t max_memory_request = 0
 
static size_t virtual_anonymous_memory = 0
 
static MagickMemoryMethods memory_methods
 

Macro Definition Documentation

◆ AcquireAlignedMemory_Actual

#define AcquireAlignedMemory_Actual   AcquireAlignedMemory_Generic

Definition at line 337 of file memory.c.

◆ ALIGNMENT_OVERHEAD

Definition at line 310 of file memory.c.

◆ BlockFooter

#define BlockFooter (   block,
  size 
)     ((size_t *) ((char *) (block)+(size)-2*sizeof(size_t)))

Definition at line 101 of file memory.c.

◆ BlockHeader

#define BlockHeader (   block)    ((size_t *) (block)-1)

Definition at line 103 of file memory.c.

◆ BlockThreshold

#define BlockThreshold   1024

Definition at line 104 of file memory.c.

◆ MaxBlockExponent

#define MaxBlockExponent   16

Definition at line 105 of file memory.c.

◆ MaxBlocks

#define MaxBlocks   ((BlockThreshold/(4*sizeof(size_t)))+MaxBlockExponent+1)

Definition at line 106 of file memory.c.

◆ MaxSegments

#define MaxSegments   1024

Definition at line 107 of file memory.c.

◆ MinMemoryRequest

#define MinMemoryRequest   "16MiB"

◆ NextBlock

#define NextBlock (   block)    ((char *) (block)+SizeOfBlock(block))

Definition at line 108 of file memory.c.

◆ NextBlockInList

#define NextBlockInList (   block)    (*(void **) (block))

Definition at line 109 of file memory.c.

◆ PreviousBlock

#define PreviousBlock (   block)    ((char *) (block)-(*((size_t *) (block)-2)))

Definition at line 110 of file memory.c.

◆ PreviousBlockBit

#define PreviousBlockBit   0x01

Definition at line 111 of file memory.c.

◆ PreviousBlockInList

#define PreviousBlockInList (   block)    (*((void **) (block)+1))

Definition at line 112 of file memory.c.

◆ SegmentSize

#define SegmentSize   (2*1024*1024)

Definition at line 113 of file memory.c.

◆ SizeMask

#define SizeMask   (~0x01)

Definition at line 114 of file memory.c.

◆ SizeOfBlock

#define SizeOfBlock (   block)    (*BlockHeader(block) & SizeMask)

Definition at line 115 of file memory.c.

Typedef Documentation

◆ DataSegmentInfo

◆ MagickMemoryMethods

◆ MemoryPool

typedef struct _MemoryPool MemoryPool

Enumeration Type Documentation

◆ VirtualMemoryType

Enumerator
UndefinedVirtualMemory 
AlignedVirtualMemory 
MapVirtualMemory 
UnalignedVirtualMemory 

Definition at line 120 of file memory.c.

Function Documentation

◆ AcquireAlignedMemory()

◆ AcquireAlignedMemory_Generic()

static void * AcquireAlignedMemory_Generic ( const size_t  size)
inlinestatic

◆ AcquireCriticalMemory()

◆ AcquireMagickMemory()

◆ AcquireQuantumMemory()

MagickExport void * AcquireQuantumMemory ( const size_t  count,
const size_t  quantum 
)

Definition at line 665 of file memory.c.

References AcquireMagickMemory(), GetMaxMemoryRequest(), HeapOverflowSanityCheckGetSize(), and MagickFalse.

Referenced by AcquireBilateralTLS(), AcquireContributionTLS(), AcquireFxInfoPrivate(), AcquireHistogramTLS(), AcquireImageColormap(), AcquireKmeansTLS(), AcquireMagickMatrix(), AcquirePixelCacheNexus(), AcquirePixelChannelMap(), AcquirePixelListTLS(), AcquirePixelTLS(), AcquirePolygonTLS(), AcquireQuantumPixels(), AcquireRandomInfoTLS(), AcquireResampleFilterTLS(), AcquireSignatureInfo(), AcquireString(), AcquireStringInfo(), AcquireUniqueSymbolicLink(), AcquireVirtualMemory(), AnnotateImage(), AutoThresholdImage(), BalanceSplayTree(), Base64Decode(), Base64Encode(), BlobToStringInfo(), CheckImageColors(), CLAHE(), Classify(), ClassifyImageColors(), CloneDrawInfo(), CloneImage(), ClonePixelCacheOnDisk(), ClonePolygonEdgesTLS(), ClutImage(), ColorDecisionListImage(), CompareImagesLayers(), ConcatenateStringInfo(), ConfigureFileToStringInfo(), ConnectedComponentsImage(), ConstantString(), ContrastStretchImage(), ConvertLatin1ToUTF8(), ConvertPathToPolygon(), ConvertPrimitiveToPath(), ConvertUTF16ToUTF8(), CopyDelegateFile(), CreateMagickThreadKey(), CustomStreamToImage(), DeleteImages(), DeskewImage(), DistortImage(), DrawDashPolygon(), EqualizeImage(), EscapeParenthesis(), EscapeString(), EvaluateImages(), ExpandFilenames(), ExportImagePixels(), FileToBlob(), FileToImage(), FileToXML(), GammaImage(), GaussJordanElimination(), GenerateCoefficients(), Get8BIMProperty(), GetCoderInfoList(), GetCoderList(), GetColorInfoList(), GetColorList(), GetCommandOptions(), GetConfigureInfoList(), GetConfigureList(), GetDelegateInfoList(), GetDelegateList(), GetExecutionPath(), GetEXIFProperty(), GetImageConvexHull(), GetImageDepth(), GetImageDistortion(), GetImageDistortions(), GetImageDynamicThreshold(), GetImageFeatures(), GetImageHistogram(), GetImageMinimumBoundingBox(), GetImageMoments(), GetImagePerceptualHash(), GetImageStatistics(), GetImageViewException(), GetIPTCProperty(), GetLocaleInfoList(), GetLocaleList(), GetLocationStatistics(), GetLogInfoList(), GetLogList(), GetMagicInfoList(), GetMagickInfoList(), GetMagickList(), GetMagicList(), GetMimeInfoList(), GetMimeList(), GetNodeInfo(), GetPathComponents(), GetPolicyInfoList(), GetPolicyList(), GetThresholdMapFile(), GetTypeInfoList(), GetTypeList(), GetVirtualPixelCacheNexus(), GradientImage(), HuffmanDecodeImage(), HuffmanEncodeImage(), IdentifyImage(), ImageListToArray(), ImagesToBlob(), ImagesToCustomStream(), ImageToBlob(), ImageToCustomStream(), ImageToFile(), ImportImagePixels(), InitFx(), InitializeIntervalTree(), InjectImageBlob(), IterateOverSplayTree(), KapurThreshold(), LinearStretchImage(), ListFiles(), LZWEncodeImage(), MontageImageList(), MorphologyPrimitive(), MotionBlurImage(), NewXMLTree(), OptimalTau(), OptimizeLayerFrames(), OTSUThreshold(), PackbitsEncodeImage(), ParseEntities(), ParseInternalDoctype(), ParseProcessingInstructions(), popen_utf8(), ReduceImageColors(), RenderHoughLines(), RenderMVGContent(), RotationalBlurImage(), SampleImage(), ScaleImage(), ScaleSpace(), SegmentImage(), SetGrayscaleImage(), SetImageDepth(), SetImageInfo(), SetStringInfoLength(), SetXMLTreeAttribute(), SortColormapByIntensity(), sRGBTransformImage(), StreamImagePixels(), StringInfoToHexString(), StringInfoToString(), StringToArgv(), StringToArrayOfDoubles(), StringToStrings(), TraceBezier(), TraceStrokePolygon(), TransformsRGBImage(), WaveImage(), and WaveletDenoiseImage().

◆ AcquireVirtualMemory()

◆ actual_base_address()

static void * actual_base_address ( void *const  p)
inlinestatic

Definition at line 322 of file memory.c.

References pointer_to_space_for_actual_base_address().

Referenced by RelinquishAlignedMemory().

◆ adjust()

static void * adjust ( void *const  p)
inlinestatic

Definition at line 332 of file memory.c.

References align_to_cache(), and reserve_space_for_actual_base_address().

Referenced by AcquireAlignedMemory_Generic(), and ClutImage().

◆ align_to_cache()

static void * align_to_cache ( void *const  p)
inlinestatic

Definition at line 327 of file memory.c.

References CACHE_ALIGNED.

Referenced by adjust().

◆ CopyMagickMemory()

MagickExport void * CopyMagickMemory ( void *magick_restrict  destination,
const void *magick_restrict  source,
const size_t  size 
)

Definition at line 837 of file memory.c.

◆ DestroyMagickMemory()

◆ GetMagickMemoryMethods()

MagickExport void GetMagickMemoryMethods ( AcquireMemoryHandler acquire_memory_handler,
ResizeMemoryHandler resize_memory_handler,
DestroyMemoryHandler destroy_memory_handler 
)

◆ GetMaxMemoryRequest()

◆ GetVirtualMemoryBlob()

◆ pointer_to_space_for_actual_base_address()

static void ** pointer_to_space_for_actual_base_address ( void *const  p)
inlinestatic

Definition at line 317 of file memory.c.

Referenced by AcquireAlignedMemory_Generic(), and actual_base_address().

◆ RelinquishAlignedMemory()

◆ RelinquishMagickMemory()

MagickExport void * RelinquishMagickMemory ( void *  memory)

Definition at line 1162 of file memory.c.

References BlockFooter, BlockHeader, _MagickMemoryMethods::destroy_memory_handler, LockSemaphoreInfo(), memory_methods, NextBlock, PreviousBlock, PreviousBlockBit, SizeOfBlock, and UnlockSemaphoreInfo().

Referenced by access_utf8(), AcquireCoderCache(), AcquireFxInfoPrivate(), AcquireMagickMatrix(), AcquirePolygonTLS(), AcquireUniqueSymbolicLink(), AddPathToXMLTree(), AnnotateImage(), AutoThresholdImage(), BalanceSplayTree(), Base64Decode(), CanonicalXMLContent(), CLAHE(), Classify(), ClearLinkedList(), ClonePixelCacheOnDisk(), ClutImage(), ColorDecisionListImage(), CompareImagesLayers(), ConnectedComponentsImage(), ContrastStretchImage(), ConvertPathToPolygon(), CopyDelegateFile(), CreateMagickThreadKey(), CustomStreamToImage(), DeInitFx(), DeleteImages(), DeleteMagickThreadKey(), DeleteNodeByValueFromSplayTree(), DeleteNodeFromSplayTree(), DeskewImage(), DestroyBilateralTLS(), DestroyBlob(), DestroyCoderNode(), DestroyColorCube(), DestroyColorElement(), DestroyConfigureElement(), DestroyContributionTLS(), DestroyCubeInfo(), DestroyCustomStreamInfo(), DestroyDelegate(), DestroyDistributeCacheInfo(), DestroyDrawInfo(), DestroyEdge(), DestroyExceptionElement(), DestroyExceptionInfo(), DestroyFxInfo(), DestroyFxRt(), DestroyHistogramTLS(), DestroyImage(), DestroyImageInfo(), DestroyImageView(), DestroyKernelInfo(), DestroyKmeansTLS(), DestroyLinkedList(), DestroyLocaleNode(), DestroyLogElement(), DestroyMagicElement(), DestroyMagickNode(), DestroyMatrixInfo(), DestroyMimeElement(), DestroyMontageInfo(), DestroyPixelCacheNexus(), DestroyPixelChannelMap(), DestroyPixelList(), DestroyPixelListTLS(), DestroyPixelTLS(), DestroyPolicyElement(), DestroyPolygonInfo(), DestroyPolygonTLS(), DestroyQuantizeInfo(), DestroyQuantumInfo(), DestroyQuantumPixels(), DestroyRandomInfo(), DestroyRandomInfoTLS(), DestroyRegistryNode(), DestroyResampleFilter(), DestroyResampleFilterTLS(), DestroyResizeFilter(), DestroyRPN(), DestroySignatureInfo(), DestroySplayTree(), DestroyStreamInfo(), DestroyString(), DestroyStringInfo(), DestroyStringList(), DestroyThresholdMap(), DestroyTimerInfo(), DestroyTokenInfo(), DestroyTypeNode(), DestroyXMLTree(), DestroyXMLTreeAttributes(), DestroyXMLTreeRoot(), DistortImage(), DrawDashPolygon(), DrawStrokePolygon(), EqualizeImage(), EvaluateImages(), ExecuteRPN(), ExpandFilenames(), ExportImagePixels(), ExternalDelegateCommand(), FileToBlob(), FileToImage(), FileToXML(), fopen_utf8(), FreeNodes(), GammaImage(), GaussJordanElimination(), GenerateCoefficients(), GetConfigureOptions(), GetConfigurePaths(), GetDelegateCommand(), GetExecutionPath(), GetHostname(), GetImageDepth(), GetImageDistortion(), GetImageDistortions(), GetImageDynamicThreshold(), GetImageEntropy(), GetImageFeatures(), GetImageKurtosis(), GetImageMean(), GetImageMedian(), GetImageMinimumBoundingBox(), GetImageMoments(), GetImagePerceptualHash(), GetImageStatistics(), GetLocaleOptions(), GetMagickHomeURL(), GetMagickProperty(), GetMultilineTypeMetrics(), GetMVGMacros(), GetNormalizedCrossCorrelationDistortion(), GetNumberColors(), GetPerceptualHashDistortion(), GetVirtualPixelCacheNexus(), GetXMLTreePath(), GetXMPProperty(), HuffmanDecodeImage(), HuffmanEncodeImage(), IdentifyImage(), ImageStat(), ImagesToBlob(), ImagesToCustomStream(), ImageToBlob(), ImageToCustomStream(), ImageToFile(), ImportImagePixels(), InitFx(), InitializeIntervalTree(), InjectImageBlob(), InsertValueInSortedLinkedList(), InvokeDelegate(), IsOptionMember(), IterateOverSplayTree(), KapurThreshold(), LinearStretchImage(), ListCoderInfo(), ListColorInfo(), ListConfigureInfo(), ListDelegateInfo(), ListFiles(), ListLocaleInfo(), ListLogInfo(), ListMagicInfo(), ListMagickInfo(), ListMimeInfo(), ListPolicyInfo(), ListTypeInfo(), LoadColorCache(), LoadConfigureCache(), LoadDelegateCache(), LoadLocaleCache(), LoadLogCache(), LoadPolicyCache(), LoadTypeCache(), LogMagickEventList(), LZWEncodeImage(), MontageImageList(), MorphologyPrimitive(), MotionBlurImage(), open_utf8(), OptimalTau(), OptimizeLayerFrames(), OTSUThreshold(), PackbitsEncodeImage(), ParseInternalDoctype(), popen_utf8(), PreviewImage(), ReadInlineImage(), ReduceImageColors(), RelinquishAlignedMemory(), RelinquishMagickMatrix(), RelinquishVirtualMemory(), remove_utf8(), RemoveElementByValueFromLinkedList(), RemoveElementFromLinkedList(), RemoveLastElementFromLinkedList(), RemoveNodeByValueFromSplayTree(), RemoveNodeFromSplayTree(), rename_utf8(), RenderMVGContent(), RenderType(), ResetSplayTree(), ResizeMagickMemory(), ResizeQuantumMemory(), RotationalBlurImage(), SampleImage(), ScaleImage(), ScaleSpace(), SegmentImage(), set_file_timestamp(), SetGrayscaleImage(), SetImageArtifact(), SetImageDepth(), SetImageInfo(), SetImageOption(), SetImageProfileInternal(), SetImageProperty(), SetImageRegistry(), SetPolicyValue(), SortColormapByIntensity(), SparseColorImage(), sRGBTransformImage(), stat_utf8(), StreamImagePixels(), StringToArgv(), TraceBezier(), TraceStrokePolygon(), TransformsRGBImage(), WaveImage(), and WaveletDenoiseImage().

◆ RelinquishVirtualMemory()

◆ reserve_space_for_actual_base_address()

static void * reserve_space_for_actual_base_address ( void *const  p)
inlinestatic

Definition at line 312 of file memory.c.

Referenced by adjust().

◆ ResetMagickMemory()

MagickExport void * ResetMagickMemory ( void *  memory,
int  c,
const size_t  size 
)

Definition at line 1290 of file memory.c.

Referenced by GetPixelInfoPixel(), and TransformSignature().

◆ ResetMaxMemoryRequest()

MagickPrivate void ResetMaxMemoryRequest ( void  )

Definition at line 1322 of file memory.c.

References max_memory_request.

◆ ResetVirtualAnonymousMemory()

MagickPrivate void ResetVirtualAnonymousMemory ( void  )

Definition at line 1345 of file memory.c.

References virtual_anonymous_memory.

Referenced by SetMagickSecurityPolicyValue().

◆ ResizeMagickMemory()

◆ ResizeQuantumMemory()

◆ SetMagickAlignedMemoryMethods()

MagickExport void SetMagickAlignedMemoryMethods ( AcquireAlignedMemoryHandler  acquire_aligned_memory_handler,
RelinquishAlignedMemoryHandler  relinquish_aligned_memory_handler 
)

◆ SetMagickMemoryMethods()

MagickExport void SetMagickMemoryMethods ( AcquireMemoryHandler  acquire_memory_handler,
ResizeMemoryHandler  resize_memory_handler,
DestroyMemoryHandler  destroy_memory_handler 
)

Variable Documentation

◆ max_memory_request

size_t max_memory_request = 0
static

Definition at line 201 of file memory.c.

Referenced by GetMaxMemoryRequest(), and ResetMaxMemoryRequest().

◆ memory_methods

MagickMemoryMethods memory_methods
static
Initial value:
=
{
}
void *(*)(*) *(* ResizeMemoryHandler)(void *, size_t) magick_alloc_size(2)
Definition: memory_.h:33
void *(* AcquireMemoryHandler)(size_t) magick_alloc_size(1)
Definition: memory_.h:31
void *(*)(*) *(*) *(* AcquireAlignedMemoryHandler)(const size_t, const size_t)
Definition: memory_.h:34
void *(*)(*) *(*) *(*)(* RelinquishAlignedMemoryHandler)(void *)
Definition: memory_.h:35
void *(*)(* DestroyMemoryHandler)(void *)
Definition: memory_.h:32

Definition at line 222 of file memory.c.

Referenced by AcquireAlignedMemory(), AcquireMagickMemory(), DestroyMagickMemory(), GetMagickMemoryMethods(), RelinquishAlignedMemory(), RelinquishMagickMemory(), ResizeMagickMemory(), SetMagickAlignedMemoryMethods(), and SetMagickMemoryMethods().

◆ virtual_anonymous_memory

size_t virtual_anonymous_memory = 0
static

Definition at line 202 of file memory.c.

Referenced by AcquireVirtualMemory(), and ResetVirtualAnonymousMemory().