From ab608058b4530c04f08238470c6f692ce0a755a5 Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Mon, 23 Jun 2003 05:55:31 +0000 Subject: [PATCH] Allocator that uses malloc()/free() git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3622 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../private/kernel/util/MallocFreeAllocator.h | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 headers/private/kernel/util/MallocFreeAllocator.h diff --git a/headers/private/kernel/util/MallocFreeAllocator.h b/headers/private/kernel/util/MallocFreeAllocator.h new file mode 100644 index 0000000000..6489648cc2 --- /dev/null +++ b/headers/private/kernel/util/MallocFreeAllocator.h @@ -0,0 +1,30 @@ +#ifndef _MALLOC_FREE_ALLOCATOR_H_ +#define _MALLOC_FREE_ALLOCATOR_H_ + +#include "Constructor.h" + +#include + +template +class MallocFreeAllocator : public Constructor { +public: + typedef DataType* Pointer; + typedef const DataType* ConstPointer; + typedef DataType& Reference; + typedef const DataType& ConstReference; + + /*! malloc()'s an object of type \c DataType and returns a + pointer to it. + */ + Pointer Allocate() { + return reinterpret_cast(malloc(sizeof(DataType))); + } + + /*! free()'s the given object. + */ + void Deallocate(Pointer object) { + free(object); + } +}; + +#endif // _MALLOC_FREE_ALLOCATOR_H_