LMMS
Loading...
Searching...
No Matches
juce_Memory.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
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
44template <typename Type, typename IntegerType>
45inline Type* snapPointerToAlignment (Type* basePointer, IntegerType alignmentBytes) noexcept
46{
47 return (Type*) ((((size_t) basePointer) + (alignmentBytes - 1)) & ~(alignmentBytes - 1));
48}
49
53template <typename Type1, typename Type2>
54inline int getAddressDifference (Type1* pointer1, Type2* pointer2) noexcept { return (int) (((const char*) pointer1) - (const char*) pointer2); }
55
59template <class Type>
60inline Type* createCopyIfNotNull (const Type* objectToCopy) { return objectToCopy != nullptr ? new Type (*objectToCopy) : nullptr; }
61
62//==============================================================================
64template <typename Type>
65inline Type readUnaligned (const void* srcPtr) noexcept
66{
67 Type value;
68 memcpy (&value, srcPtr, sizeof (Type));
69 return value;
70}
71
73template <typename Type>
74inline void writeUnaligned (void* dstPtr, Type value) noexcept
75{
76 memcpy (dstPtr, &value, sizeof (Type));
77}
78
79//==============================================================================
87template <typename Type, typename std::enable_if<std::is_pointer<Type>::value, int>::type = 0>
88inline Type unalignedPointerCast (void* ptr) noexcept
89{
90 return reinterpret_cast<Type> (ptr);
91}
92
100template <typename Type, typename std::enable_if<std::is_pointer<Type>::value, int>::type = 0>
101inline Type unalignedPointerCast (const void* ptr) noexcept
102{
103 return reinterpret_cast<Type> (ptr);
104}
105
110template <typename Type, typename IntegerType>
111inline Type* addBytesToPointer (Type* basePointer, IntegerType bytes) noexcept
112{
113 return unalignedPointerCast<Type*> (reinterpret_cast<char*> (basePointer) + bytes);
114}
115
120template <typename Type, typename IntegerType>
121inline const Type* addBytesToPointer (const Type* basePointer, IntegerType bytes) noexcept
122{
123 return unalignedPointerCast<const Type*> (reinterpret_cast<const char*> (basePointer) + bytes);
124}
125
126//==============================================================================
127#if JUCE_MAC || JUCE_IOS || DOXYGEN
128
134 class JUCE_API ScopedAutoReleasePool
135 {
136 public:
137 ScopedAutoReleasePool();
138 ~ScopedAutoReleasePool();
139
140 private:
141 void* pool;
142
143 JUCE_DECLARE_NON_COPYABLE (ScopedAutoReleasePool)
144 };
145
151#if (JUCE_COMPILER_SUPPORTS_ARC && defined (__OBJC__)) || DOXYGEN
152 #define JUCE_AUTORELEASEPOOL @autoreleasepool
153#else
154 #define JUCE_AUTORELEASEPOOL const juce::ScopedAutoReleasePool JUCE_JOIN_MACRO (autoReleasePool_, __LINE__);
155#endif
156
157#else
158 #define JUCE_AUTORELEASEPOOL
159#endif
160
161//==============================================================================
162/* In a Windows DLL build, we'll expose some malloc/free functions that live inside the DLL, and use these for
163 allocating all the objects - that way all juce objects in the DLL and in the host will live in the same heap,
164 avoiding problems when an object is created in one module and passed across to another where it is deleted.
165 By piggy-backing on the JUCE_LEAK_DETECTOR macro, these allocators can be injected into most juce classes.
166*/
167#if JUCE_MSVC && (defined (JUCE_DLL) || defined (JUCE_DLL_BUILD)) && ! (JUCE_DISABLE_DLL_ALLOCATORS || DOXYGEN)
168 extern JUCE_API void* juceDLL_malloc (size_t);
169 extern JUCE_API void juceDLL_free (void*);
170
171 #define JUCE_LEAK_DETECTOR(OwnerClass) public:\
172 static void* operator new (size_t sz) { return juce::juceDLL_malloc (sz); } \
173 static void* operator new (size_t, void* p) { return p; } \
174 static void operator delete (void* p) { juce::juceDLL_free (p); } \
175 static void operator delete (void*, void*) {}
176#endif
177
178//==============================================================================
182#ifndef juce_UseDebuggingNewOperator
183 #define juce_UseDebuggingNewOperator
184#endif
185
194template <typename T>
195std::unique_ptr<T> rawToUniquePtr (T* ptr)
196{
197 return std::unique_ptr<T> (ptr);
198}
199
200} // namespace juce
pool_t pool
Definition Util.cpp:167
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
static PuglViewHint int value
Definition pugl.h:1708
#define JUCE_DECLARE_NON_COPYABLE(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
Type * createCopyIfNotNull(const Type *objectToCopy)
Definition juce_Memory.h:60
void zerostruct(Type &structure) noexcept
Definition juce_Memory.h:32
Type unalignedPointerCast(void *ptr) noexcept
Definition juce_Memory.h:88
int getAddressDifference(Type1 *pointer1, Type2 *pointer2) noexcept
Definition juce_Memory.h:54
jack_client_t client jack_client_t client jack_client_t client jack_client_t JackInfoShutdownCallback void arg jack_client_t jack_port_t port void func jack_client_t const char const char unsigned long flags const jack_port_t port jack_client_t jack_port_id_t port_id const jack_port_t const char port_name const jack_port_t port void * ptr
Definition juce_linux_JackAudio.cpp:79
Type readUnaligned(const void *srcPtr) noexcept
Definition juce_Memory.h:65
void deleteAndZero(Type &pointer)
Definition juce_Memory.h:40
Type * addBytesToPointer(Type *basePointer, IntegerType bytes) noexcept
Definition juce_Memory.h:111
void writeUnaligned(void *dstPtr, Type value) noexcept
Definition juce_Memory.h:74
Type * snapPointerToAlignment(Type *basePointer, IntegerType alignmentBytes) noexcept
Definition juce_Memory.h:45
std::unique_ptr< T > rawToUniquePtr(T *ptr)
Definition juce_Memory.h:195
void zeromem(void *memory, size_t numBytes) noexcept
Definition juce_Memory.h:28
memcpy(hh, h, RAND_HEAD_LEN)