openshot-audio  0.1.2
juce_Memory.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the juce_core module of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission to use, copy, modify, and/or distribute this software for any purpose with
8  or without fee is hereby granted, provided that the above copyright notice and this
9  permission notice appear in all copies.
10 
11  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12  TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
13  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
15  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 
18  ------------------------------------------------------------------------------
19 
20  NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
21  All other JUCE modules are covered by a dual GPL/commercial license, so if you are
22  using any other modules, be sure to check that you also comply with their license.
23 
24  For more details, visit www.juce.com
25 
26  ==============================================================================
27 */
28 
29 #ifndef JUCE_MEMORY_H_INCLUDED
30 #define JUCE_MEMORY_H_INCLUDED
31 
32 //==============================================================================
34 inline void zeromem (void* memory, size_t numBytes) noexcept { memset (memory, 0, numBytes); }
35 
37 template <typename Type>
38 inline void zerostruct (Type& structure) noexcept { memset (&structure, 0, sizeof (structure)); }
39 
45 template <typename Type>
46 inline void deleteAndZero (Type& pointer) { delete pointer; pointer = nullptr; }
47 
52 template <typename Type, typename IntegerType>
53 inline Type* addBytesToPointer (Type* basePointer, IntegerType bytes) noexcept { return (Type*) (((char*) basePointer) + bytes); }
54 
58 template <typename Type1, typename Type2>
59 inline int getAddressDifference (Type1* pointer1, Type2* pointer2) noexcept { return (int) (((const char*) pointer1) - (const char*) pointer2); }
60 
64 template <class Type>
65 inline Type* createCopyIfNotNull (const Type* objectToCopy) { return objectToCopy != nullptr ? new Type (*objectToCopy) : nullptr; }
66 
67 //==============================================================================
69 template <typename Type>
70 inline Type readUnaligned (const void* srcPtr) noexcept
71 {
72  Type value;
73  memcpy (&value, srcPtr, sizeof (Type));
74 
75  return value;
76 }
77 
79 template <typename Type>
80 inline void writeUnaligned (void* dstPtr, Type value) noexcept
81 {
82  memcpy (dstPtr, &value, sizeof(Type));
83 }
84 
85 //==============================================================================
86 #if JUCE_MAC || JUCE_IOS || DOXYGEN
87 
91  class JUCE_API ScopedAutoReleasePool
92  {
93  public:
94  ScopedAutoReleasePool();
95  ~ScopedAutoReleasePool();
96 
97  private:
98  void* pool;
99 
100  JUCE_DECLARE_NON_COPYABLE (ScopedAutoReleasePool)
101  };
102 
108 #if (JUCE_COMPILER_SUPPORTS_ARC && defined (__OBJC__)) || DOXYGEN
109  #define JUCE_AUTORELEASEPOOL @autoreleasepool
110 #else
111  #define JUCE_AUTORELEASEPOOL const juce::ScopedAutoReleasePool JUCE_JOIN_MACRO (autoReleasePool_, __LINE__);
112 #endif
113 
114 #else
115  #define JUCE_AUTORELEASEPOOL
116 #endif
117 
118 //==============================================================================
119 /* In a Windows DLL build, we'll expose some malloc/free functions that live inside the DLL, and use these for
120  allocating all the objects - that way all juce objects in the DLL and in the host will live in the same heap,
121  avoiding problems when an object is created in one module and passed across to another where it is deleted.
122  By piggy-backing on the JUCE_LEAK_DETECTOR macro, these allocators can be injected into most juce classes.
123 */
124 #if JUCE_MSVC && (defined (JUCE_DLL) || defined (JUCE_DLL_BUILD)) && ! (JUCE_DISABLE_DLL_ALLOCATORS || DOXYGEN)
125  extern JUCE_API void* juceDLL_malloc (size_t);
126  extern JUCE_API void juceDLL_free (void*);
127 
128  #define JUCE_LEAK_DETECTOR(OwnerClass) public:\
129  static void* operator new (size_t sz) { return juce::juceDLL_malloc (sz); } \
130  static void* operator new (size_t, void* p) { return p; } \
131  static void operator delete (void* p) { juce::juceDLL_free (p); } \
132  static void operator delete (void*, void*) {}
133 #endif
134 
135 //==============================================================================
139 #ifndef juce_UseDebuggingNewOperator
140  #define juce_UseDebuggingNewOperator
141 #endif
142 
143 
144 #endif // JUCE_MEMORY_H_INCLUDED
#define noexcept
Definition: juce_CompilerSupport.h:141
void zeromem(void *memory, size_t numBytes) noexcept
Definition: juce_Memory.h:34
Type * addBytesToPointer(Type *basePointer, IntegerType bytes) noexcept
Definition: juce_Memory.h:53
#define JUCE_API
Definition: juce_StandardHeader.h:139
void deleteAndZero(Type &pointer)
Definition: juce_Memory.h:46
void zerostruct(Type &structure) noexcept
Definition: juce_Memory.h:38
Type * createCopyIfNotNull(const Type *objectToCopy)
Definition: juce_Memory.h:65
void writeUnaligned(void *dstPtr, Type value) noexcept
Definition: juce_Memory.h:80
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition: juce_PlatformDefs.h:191
Type readUnaligned(const void *srcPtr) noexcept
Definition: juce_Memory.h:70
int getAddressDifference(Type1 *pointer1, Type2 *pointer2) noexcept
Definition: juce_Memory.h:59