xref: /haiku/headers/private/kernel/util/MallocFreeAllocator.h (revision cbe0a0c436162d78cc3f92a305b64918c839d079)
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