MagickCore 7.1.1-43
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
memory-private.h
1/*
2 Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
4
5 You may not use this file except in compliance with the License. You may
6 obtain a copy of the License at
7
8 https://imagemagick.org/script/license.php
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 MagickCore private memory methods.
17*/
18#ifndef MAGICKCORE_MEMORY_PRIVATE_H
19#define MAGICKCORE_MEMORY_PRIVATE_H
20
21#include "MagickCore/magick-config.h"
22#include <stdint.h>
23
24#if defined(__cplusplus) || defined(c_plusplus)
25extern "C" {
26#endif
27
28#if defined(__powerpc__)
29# define CACHE_LINE_SIZE (16 * MAGICKCORE_SIZEOF_VOID_P)
30#else
31# define CACHE_LINE_SIZE (8 * MAGICKCORE_SIZEOF_VOID_P)
32#endif
33
34#define CACHE_ALIGNED(n) MAGICKCORE_ALIGN_UP(n,CACHE_LINE_SIZE)
35
36#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 6))
37#if !defined(__ICC)
38#define MagickAssumeAligned(address) \
39 __builtin_assume_aligned((address),CACHE_LINE_SIZE)
40#else
41#define MagickAssumeAligned(address) (address)
42#endif
43#else
44#define MagickAssumeAligned(address) (address)
45#endif
46
47static inline MagickBooleanType HeapOverflowCheckAdd(const size_t size,
48 const size_t increment)
49{
50 if (size > (SIZE_MAX-increment))
51 {
52 errno=ENOMEM;
53 return(MagickTrue);
54 }
55 return(MagickFalse);
56}
57
58static inline size_t OverAllocateMemory(const size_t length)
59{
60 size_t
61 extent;
62
63 /*
64 Over allocate memory, typically used when concatenating strings.
65 */
66 extent=length;
67 if (extent < 131072)
68 for (extent=256; extent < length; extent*=2);
69 return(extent);
70}
71
72extern MagickPrivate MagickBooleanType
73 ShredMagickMemory(void *,const size_t);
74
75extern MagickPrivate void
76 ResetMaxMemoryRequest(void),
77 ResetVirtualAnonymousMemory(void),
78 SetMaxMemoryRequest(const MagickSizeType),
79 SetMaxProfileSize(const MagickSizeType);
80
81#if defined(__cplusplus) || defined(c_plusplus)
82}
83#endif
84
85#endif