28inline void zeromem (
void* memory,
size_t numBytes)
noexcept {
memset (memory, 0, numBytes); }
31template <
typename Type>
32inline void zerostruct (Type& structure)
noexcept {
memset ((
void*) &structure, 0,
sizeof (structure)); }
39template <
typename Type>
40inline void deleteAndZero (Type& pointer) {
delete pointer; pointer =
nullptr; }
44template <
typename Type,
typename IntegerType>
47 return (Type*) ((((
size_t) basePointer) + (alignmentBytes - 1)) & ~(alignmentBytes - 1));
53template <
typename Type1,
typename Type2>
54inline int getAddressDifference (Type1* pointer1, Type2* pointer2)
noexcept {
return (
int) (((
const char*) pointer1) - (
const char*) pointer2); }
60inline Type*
createCopyIfNotNull (
const Type* objectToCopy) {
return objectToCopy !=
nullptr ?
new Type (*objectToCopy) :
nullptr; }
64template <
typename Type>
68 memcpy (&value, srcPtr,
sizeof (Type));
73template <
typename Type>
76 memcpy (dstPtr, &value,
sizeof (Type));
87template <
typename Type>
91 return reinterpret_cast<Type
> (ptr);
101template <
typename Type>
105 return reinterpret_cast<Type
> (ptr);
112template <
typename Type,
typename IntegerType>
115 return unalignedPointerCast<Type*> (
reinterpret_cast<char*
> (basePointer) + bytes);
122template <
typename Type,
typename IntegerType>
125 return unalignedPointerCast<const Type*> (
reinterpret_cast<const char*
> (basePointer) + bytes);
129#if JUCE_MAC || JUCE_IOS || DOXYGEN
153#if (JUCE_COMPILER_SUPPORTS_ARC && defined (__OBJC__)) || DOXYGEN
154 #define JUCE_AUTORELEASEPOOL @autoreleasepool
156 #define JUCE_AUTORELEASEPOOL const juce::ScopedAutoReleasePool JUCE_JOIN_MACRO (autoReleasePool_, __LINE__);
160 #define JUCE_AUTORELEASEPOOL
169#if JUCE_MSVC && (defined (JUCE_DLL) || defined (JUCE_DLL_BUILD)) && ! (JUCE_DISABLE_DLL_ALLOCATORS || DOXYGEN)
170 extern JUCE_API
void* juceDLL_malloc (
size_t);
171 extern JUCE_API
void juceDLL_free (
void*);
173 #define JUCE_LEAK_DETECTOR(OwnerClass) public:\
174 static void* operator new (size_t sz) { return juce::juceDLL_malloc (sz); } \
175 static void* operator new (size_t, void* p) { return p; } \
176 static void operator delete (void* p) { juce::juceDLL_free (p); } \
177 static void operator delete (void*, void*) {}
184#ifndef juce_UseDebuggingNewOperator
185 #define juce_UseDebuggingNewOperator
A handy C++ wrapper that creates and deletes an NSAutoreleasePool object using RAII.
Type * createCopyIfNotNull(const Type *objectToCopy)
If a pointer is non-null, this returns a new copy of the object that it points to,...
void zerostruct(Type &structure) noexcept
Overwrites a structure or object with zeros.
int getAddressDifference(Type1 *pointer1, Type2 *pointer2) noexcept
A handy function which returns the difference between any two pointers, in bytes.
Type readUnaligned(const void *srcPtr) noexcept
A handy function to read un-aligned memory without a performance penalty or bus-error.
void deleteAndZero(Type &pointer)
Delete an object pointer, and sets the pointer to null.
Type * addBytesToPointer(Type *basePointer, IntegerType bytes) noexcept
A handy function which adds a number of bytes to any type of pointer and returns the result.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
void writeUnaligned(void *dstPtr, Type value) noexcept
A handy function to write un-aligned memory without a performance penalty or bus-error.
Type * snapPointerToAlignment(Type *basePointer, IntegerType alignmentBytes) noexcept
A handy function to round up a pointer to the nearest multiple of a given number of bytes.
std::unique_ptr< T > rawToUniquePtr(T *ptr)
Converts an owning raw pointer into a unique_ptr, deriving the type of the unique_ptr automatically.
void zeromem(void *memory, size_t numBytes) noexcept
Fills a block of memory with zeros.