#ifndef WTF_DefaultAllocator_h
#define WTF_DefaultAllocator_h
#include "wtf/Assertions.h"
#include "wtf/FastAllocBase.h"
#include "wtf/PartitionAlloc.h"
#include "wtf/WTF.h"
#include <string.h>
namespace WTF {
class DefaultAllocatorDummyVisitor;
class DefaultAllocatorQuantizer {
public:
template<typename T>
static size_t quantizedSize(size_t count)
{
RELEASE_ASSERT(count <= kMaxUnquantizedAllocation / sizeof(T));
return partitionAllocActualSize(Partitions::getBufferPartition(), count * sizeof(T));
}
static const size_t kMaxUnquantizedAllocation = kGenericMaxDirectMapped;
};
class DefaultAllocator {
public:
typedef DefaultAllocatorQuantizer Quantizer;
typedef DefaultAllocatorDummyVisitor Visitor;
static const bool isGarbageCollected = false;
template<typename T, typename Traits>
struct VectorBackingHelper {
typedef void Type;
};
template<typename T>
struct HashTableBackingHelper {
typedef void Type;
};
template <typename Return, typename Metadata>
static Return backingMalloc(size_t size)
{
return reinterpret_cast<Return>(partitionAllocGeneric(Partitions::getBufferPartition(), size));
}
template <typename Return, typename Metadata>
static Return zeroedBackingMalloc(size_t size)
{
void* result = partitionAllocGeneric(Partitions::getBufferPartition(), size);
memset(result, 0, size);
return reinterpret_cast<Return>(result);
}
template <typename Return, typename Metadata>
static Return malloc(size_t size)
{
return reinterpret_cast<Return>(fastMalloc(size));
}
static void backingFree(void* address)
{
partitionFreeGeneric(Partitions::getBufferPartition(), address);
}
static void free(void* address)
{
fastFree(address);
}
template<typename T>
static void* newArray(size_t bytes)
{
return malloc<void*, void>(bytes);
}
static void
deleteArray(void* ptr)
{
free(ptr);
}
static void markNoTracing(...)
{
ASSERT_NOT_REACHED();
}
static void registerWeakMembers(...)
{
ASSERT_NOT_REACHED();
}
template<typename T, typename Traits>
static void trace(...)
{
ASSERT_NOT_REACHED();
}
template<typename T>
struct OtherType {
typedef T* Type;
};
template<typename T>
static T& getOther(T* other)
{
return *other;
}
};
class DefaultAllocatorDummyVisitor {
public:
template<typename T> inline bool isAlive(T obj)
{
ASSERT_NOT_REACHED();
return false;
}
};
}
using WTF::DefaultAllocator;
#endif