xref: /haiku/headers/private/kernel/util/MallocFreeAllocator.h (revision a5a3b2d9a3d95cbae71eaf371708c73a1780ac0d)
1 #ifndef _MALLOC_FREE_ALLOCATOR_H_
2 #define _MALLOC_FREE_ALLOCATOR_H_
3 
4 #include <util/Constructor.h>
5 
6 #include <malloc.h>
7 
8 template <class DataType>
9 class MallocFreeAllocator : public Constructor<DataType> {
10 public:
11 	typedef DataType* Pointer;
12 	typedef const DataType* ConstPointer;
13 	typedef DataType& Reference;
14 	typedef const DataType& ConstReference;
15 
16 	/*! malloc()'s an object of type \c DataType and returns a
17 		pointer to it.
18 	*/
19 	Pointer Allocate() {
20 		return reinterpret_cast<Pointer>(malloc(sizeof(DataType)));
21 	}
22 
23 	/*! free()'s the given object.
24 	*/
25 	void Deallocate(Pointer object) {
26 		free(object);
27 	}
28 };
29 
30 #endif	// _MALLOC_FREE_ALLOCATOR_H_
31