#ifndef WTF_FastMalloc_h
#define WTF_FastMalloc_h
#include "Platform.h"
#include <stdlib.h>
#include <new>
namespace WTF {
void* fastMalloc(size_t n);
void* fastZeroedMalloc(size_t n);
void* fastCalloc(size_t n_elements, size_t element_size);
void* fastRealloc(void* p, size_t n);
void* tryFastMalloc(size_t n);
void* tryFastZeroedMalloc(size_t n);
void* tryFastCalloc(size_t n_elements, size_t element_size);
void* tryFastRealloc(void* p, size_t n);
void fastFree(void* p);
#ifndef NDEBUG
void fastMallocForbid();
void fastMallocAllow();
#endif
void releaseFastMallocFreeMemory();
struct FastMallocStatistics {
size_t heapSize;
size_t freeSizeInHeap;
size_t freeSizeInCaches;
size_t returnedSize;
};
FastMallocStatistics fastMallocStatistics();
typedef unsigned long long AllocAlignmentInteger;
namespace Internal {
enum AllocType { AllocTypeMalloc = 0x375d6750, AllocTypeClassNew, AllocTypeClassNewArray, AllocTypeFastNew, AllocTypeFastNewArray, AllocTypeNew, AllocTypeNewArray };
}
#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
namespace Internal {
inline AllocType fastMallocMatchValidationType(const void* p)
{
const AllocAlignmentInteger* type = static_cast<const AllocAlignmentInteger*>(p) - 1;
return static_cast<AllocType>(*type);
}
inline AllocAlignmentInteger* fastMallocMatchValidationValue(void* p)
{
return reinterpret_cast<AllocAlignmentInteger*>(static_cast<char*>(p) - sizeof(AllocAlignmentInteger));
}
inline void setFastMallocMatchValidationType(void* p, AllocType allocType)
{
AllocAlignmentInteger* type = static_cast<AllocAlignmentInteger*>(p) - 1;
*type = static_cast<AllocAlignmentInteger>(allocType);
}
void fastMallocMatchFailed(void* p);
}
inline void fastMallocMatchValidateMalloc(void* p, Internal::AllocType allocType)
{
if (!p)
return;
Internal::setFastMallocMatchValidationType(p, allocType);
}
inline void fastMallocMatchValidateFree(void* p, Internal::AllocType allocType)
{
if (!p)
return;
if (Internal::fastMallocMatchValidationType(p) != allocType)
Internal::fastMallocMatchFailed(p);
Internal::setFastMallocMatchValidationType(p, Internal::AllocTypeMalloc); }
#else
inline void fastMallocMatchValidateMalloc(void*, Internal::AllocType)
{
}
inline void fastMallocMatchValidateFree(void*, Internal::AllocType)
{
}
#endif
}
using WTF::fastMalloc;
using WTF::fastZeroedMalloc;
using WTF::fastCalloc;
using WTF::fastRealloc;
using WTF::tryFastMalloc;
using WTF::tryFastZeroedMalloc;
using WTF::tryFastCalloc;
using WTF::tryFastRealloc;
using WTF::fastFree;
#ifndef NDEBUG
using WTF::fastMallocForbid;
using WTF::fastMallocAllow;
#endif
#if COMPILER(GCC) && PLATFORM(DARWIN)
#define WTF_PRIVATE_INLINE __private_extern__ inline __attribute__((always_inline))
#elif COMPILER(GCC)
#define WTF_PRIVATE_INLINE inline __attribute__((always_inline))
#elif COMPILER(MSVC)
#define WTF_PRIVATE_INLINE __forceinline
#else
#define WTF_PRIVATE_INLINE inline
#endif
#ifndef _CRTDBG_MAP_ALLOC
#if !defined(USE_SYSTEM_MALLOC) || !(USE_SYSTEM_MALLOC)
WTF_PRIVATE_INLINE void* operator new(size_t s) { return fastMalloc(s); }
WTF_PRIVATE_INLINE void operator delete(void* p) { fastFree(p); }
WTF_PRIVATE_INLINE void* operator new[](size_t s) { return fastMalloc(s); }
WTF_PRIVATE_INLINE void operator delete[](void* p) { fastFree(p); }
#if PLATFORM(WINCE)
WTF_PRIVATE_INLINE void* operator new(size_t s, const std::nothrow_t&) throw() { return fastMalloc(s); }
WTF_PRIVATE_INLINE void operator delete(void* p, const std::nothrow_t&) throw() { fastFree(p); }
WTF_PRIVATE_INLINE void* operator new[](size_t s, const std::nothrow_t&) throw() { return fastMalloc(s); }
WTF_PRIVATE_INLINE void operator delete[](void* p, const std::nothrow_t&) throw() { fastFree(p); }
#endif
#endif
#endif // _CRTDBG_MAP_ALLOC
#endif