OpenShot Audio Library | OpenShotAudio: juce_Memory.h Source File

OpenShot Audio Library | OpenShotAudio 0.3.0

Loading...
Searching...
No Matches
juce_Memory.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
28inline void zeromem (void* memory, size_t numBytes) noexcept { memset (memory, 0, numBytes); }
29
31template <typename Type>
32inline void zerostruct (Type& structure) noexcept { memset ((void*) &structure, 0, sizeof (structure)); }
33
39template <typename Type>
40inline void deleteAndZero (Type& pointer) { delete pointer; pointer = nullptr; }
41
46template <typename Type, typename IntegerType>
47inline Type* addBytesToPointer (Type* basePointer, IntegerType bytes) noexcept { return reinterpret_cast<Type*> (const_cast<char*> (reinterpret_cast<const char*> (basePointer)) + bytes); }
48
51template <typename Type, typename IntegerType>
52inline Type* snapPointerToAlignment (Type* basePointer, IntegerType alignmentBytes) noexcept
53{
54 return (Type*) ((((size_t) basePointer) + (alignmentBytes - 1)) & ~(alignmentBytes - 1));
55}
56
60template <typename Type1, typename Type2>
61inline int getAddressDifference (Type1* pointer1, Type2* pointer2) noexcept { return (int) (((const char*) pointer1) - (const char*) pointer2); }
62
66template <class Type>
67inline Type* createCopyIfNotNull (const Type* objectToCopy) { return objectToCopy != nullptr ? new Type (*objectToCopy) : nullptr; }
68
69//==============================================================================
71template <typename Type>
72inline Type readUnaligned (const void* srcPtr) noexcept
73{
74 Type value;
75 memcpy (&value, srcPtr, sizeof (Type));
76 return value;
77}
78
80template <typename Type>
81inline void writeUnaligned (void* dstPtr, Type value) noexcept
82{
83 memcpy (dstPtr, &value, sizeof (Type));
84}
85
86//==============================================================================
87#if JUCE_MAC || JUCE_IOS || DOXYGEN
88
94 class JUCE_API ScopedAutoReleasePool
95 {
96 public:
97 ScopedAutoReleasePool();
98 ~ScopedAutoReleasePool();
99
100 private:
101 void* pool;
102
103 JUCE_DECLARE_NON_COPYABLE (ScopedAutoReleasePool)
104 };
105
111#if (JUCE_COMPILER_SUPPORTS_ARC && defined (__OBJC__)) || DOXYGEN
112 #define JUCE_AUTORELEASEPOOL @autoreleasepool
113#else
114 #define JUCE_AUTORELEASEPOOL const juce::ScopedAutoReleasePool JUCE_JOIN_MACRO (autoReleasePool_, __LINE__);
115#endif
116
117#else
118 #define JUCE_AUTORELEASEPOOL
119#endif
120
121//==============================================================================
122/* In a Windows DLL build, we'll expose some malloc/free functions that live inside the DLL, and use these for
123 allocating all the objects - that way all juce objects in the DLL and in the host will live in the same heap,
124 avoiding problems when an object is created in one module and passed across to another where it is deleted.
125 By piggy-backing on the JUCE_LEAK_DETECTOR macro, these allocators can be injected into most juce classes.
126*/
127#if JUCE_MSVC && (defined (JUCE_DLL) || defined (JUCE_DLL_BUILD)) && ! (JUCE_DISABLE_DLL_ALLOCATORS || DOXYGEN)
128 extern JUCE_API void* juceDLL_malloc (size_t);
129 extern JUCE_API void juceDLL_free (void*);
130
131 #define JUCE_LEAK_DETECTOR(OwnerClass) public:\
132 static void* operator new (size_t sz) { return juce::juceDLL_malloc (sz); } \
133 static void* operator new (size_t, void* p) { return p; } \
134 static void operator delete (void* p) { juce::juceDLL_free (p); } \
135 static void operator delete (void*, void*) {}
136#endif
137
138//==============================================================================
142#ifndef juce_UseDebuggingNewOperator
143 #define juce_UseDebuggingNewOperator
144#endif
145
146} // namespace juce