1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine" and the "irrXML" project.
3
// For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h
5
#ifndef __IRR_ALLOCATOR_H_INCLUDED__
6
#define __IRR_ALLOCATOR_H_INCLUDED__
10
// necessary for older compilers
18
#ifdef DEBUG_CLIENTBLOCK
19
#undef DEBUG_CLIENTBLOCK
20
#define DEBUG_CLIENTBLOCK new
23
//! Very simple allocator implementation, containers using it can be used across dll boundaries
30
virtual ~irrAllocator() {}
32
//! Allocate memory for an array of objects
33
T* allocate(size_t cnt)
35
return (T*)internal_new(cnt* sizeof(T));
38
//! Deallocate memory for an array of objects
39
void deallocate(T* ptr)
44
//! Construct an element
45
void construct(T* ptr, const T&e)
47
new ((void*)ptr) T(e);
50
//! Destruct an element
58
virtual void* internal_new(size_t cnt)
60
return operator new(cnt);
63
virtual void internal_delete(void* ptr)
71
//! Fast allocator, only to be used in containers inside the same memory heap.
72
/** Containers using it are NOT able to be used it across dll boundaries. Use this
73
when using in an internal class or function or when compiled into a static lib */
75
class irrAllocatorFast
79
//! Allocate memory for an array of objects
80
T* allocate(size_t cnt)
82
return (T*)operator new(cnt* sizeof(T));
85
//! Deallocate memory for an array of objects
86
void deallocate(T* ptr)
91
//! Construct an element
92
void construct(T* ptr, const T&e)
94
new ((void*)ptr) T(e);
97
//! Destruct an element
106
#ifdef DEBUG_CLIENTBLOCK
107
#undef DEBUG_CLIENTBLOCK
108
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
111
//! defines an allocation strategy
114
ALLOC_STRATEGY_SAFE = 0,
115
ALLOC_STRATEGY_DOUBLE = 1,
116
ALLOC_STRATEGY_SQRT = 2
120
} // end namespace core
121
} // end namespace irr