Loading...
Searching...
No Matches
irrAllocator.h
Go to the documentation of this file.
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine" and the "irrXML" project.
// For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h
#ifndef __IRR_ALLOCATOR_H_INCLUDED__
#define __IRR_ALLOCATOR_H_INCLUDED__
#include "irrTypes.h"
#include <new>
// necessary for older compilers
#include <memory.h>
namespace irr
{
namespace core
{
#ifdef DEBUG_CLIENTBLOCK
#undef DEBUG_CLIENTBLOCK
#define DEBUG_CLIENTBLOCK new
#endif
template<typename T>
class irrAllocator
{
public:
virtual ~irrAllocator() {}
T* allocate(size_t cnt)
{
return (T*)internal_new(cnt* sizeof(T));
}
void deallocate(T* ptr)
{
internal_delete(ptr);
}
void construct(T* ptr, const T&e)
{
new ((void*)ptr) T(e);
}
void destruct(T* ptr)
{
ptr->~T();
}
protected:
virtual void* internal_new(size_t cnt)
{
return operator new(cnt);
}
virtual void internal_delete(void* ptr)
{
operator delete(ptr);
}
};
template<typename T>
class irrAllocatorFast
{
public:
T* allocate(size_t cnt)
{
return (T*)operator new(cnt* sizeof(T));
}
void deallocate(T* ptr)
{
operator delete(ptr);
}
void construct(T* ptr, const T&e)
{
new ((void*)ptr) T(e);
}
void destruct(T* ptr)
{
ptr->~T();
}
};
#ifdef DEBUG_CLIENTBLOCK
#undef DEBUG_CLIENTBLOCK
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#endif
enum eAllocStrategy
{
ALLOC_STRATEGY_SAFE = 0,
ALLOC_STRATEGY_DOUBLE = 1,
ALLOC_STRATEGY_SQRT = 2
};
} // end namespace core
} // end namespace irr
#endif
irr::core::irrAllocatorFast
Fast allocator, only to be used in containers inside the same memory heap.
Definition irrAllocator.h:76
irr::core::irrAllocatorFast::construct
void construct(T *ptr, const T &e)
Construct an element.
Definition irrAllocator.h:92
irr::core::irrAllocatorFast::destruct
void destruct(T *ptr)
Destruct an element.
Definition irrAllocator.h:98
irr::core::irrAllocatorFast::deallocate
void deallocate(T *ptr)
Deallocate memory for an array of objects.
Definition irrAllocator.h:86
irr::core::irrAllocatorFast::allocate
T * allocate(size_t cnt)
Allocate memory for an array of objects.
Definition irrAllocator.h:80
irr::core::irrAllocator
Very simple allocator implementation, containers using it can be used across dll boundaries.
Definition irrAllocator.h:26
irr::core::irrAllocator::construct
void construct(T *ptr, const T &e)
Construct an element.
Definition irrAllocator.h:45
irr::core::irrAllocator::destruct
void destruct(T *ptr)
Destruct an element.
Definition irrAllocator.h:51
irr::core::irrAllocator::deallocate
void deallocate(T *ptr)
Deallocate memory for an array of objects.
Definition irrAllocator.h:39
irr::core::irrAllocator::allocate
T * allocate(size_t cnt)
Allocate memory for an array of objects.
Definition irrAllocator.h:33
irr::core::irrAllocator::internal_delete
virtual void internal_delete(void *ptr)
Definition irrAllocator.h:63
irr::core::irrAllocator::internal_new
virtual void * internal_new(size_t cnt)
Definition irrAllocator.h:58
irr::core::irrAllocator::~irrAllocator
virtual ~irrAllocator()
Destructor.
Definition irrAllocator.h:30
irrTypes.h
irr::core
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition aabbox3d.h:15
irr::core::eAllocStrategy
eAllocStrategy
defines an allocation strategy
Definition irrAllocator.h:113
irr::core::ALLOC_STRATEGY_DOUBLE
@ ALLOC_STRATEGY_DOUBLE
Definition irrAllocator.h:115
irr::core::ALLOC_STRATEGY_SAFE
@ ALLOC_STRATEGY_SAFE
Definition irrAllocator.h:114
irr::core::ALLOC_STRATEGY_SQRT
@ ALLOC_STRATEGY_SQRT
Definition irrAllocator.h:116
irr
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
- Irrlicht Engine Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on for Irrlicht 3D Engine by Doxygen 1.15.0