1
0
mirror of https://github.com/UzixLS/KernelEx.git synced 2025-07-19 07:21:20 +03:00

import KernelEx-4.5-Beta1

This commit is contained in:
UzixLS
2018-11-03 16:21:13 +03:00
parent d6aad6c6c5
commit 09929b2b7d
392 changed files with 17832 additions and 2491 deletions

113
common/winheap_allocator.hpp Executable file
View File

@ -0,0 +1,113 @@
#include <windows.h>
#include "debug.h"
template <class T>
class winheap_allocator
{
public:
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
template <class U>
struct rebind { typedef winheap_allocator<U> other; };
winheap_allocator(HANDLE heap)
{
this->heap = heap;
}
// winheap_allocator(const winheap_allocator& a)
// {
// heap = a.heap;
// }
template <class U>
winheap_allocator(const winheap_allocator<U>& a)
{
heap = a.heap;
}
~winheap_allocator()
{
}
pointer address(reference x) const
{
return &x;
}
const_pointer address(const_reference x) const
{
return x;
}
pointer allocate(size_type n, const_pointer = 0)
{
void* p = HeapAlloc(heap, 0, n * sizeof(T));
// if (!p)
// throw std::bad_alloc();
return static_cast<pointer>(p);
}
char* _Charalloc(size_type n)
{
return rebind<char>::other(*this).allocate(n, (char*) 0);
}
void deallocate(void* p, size_type)
{
BOOL ret = HeapFree(heap, 0, p);
DBGASSERT(ret == TRUE);
}
size_type max_size() const
{
return static_cast<size_type>(-1) / sizeof(T);
}
void construct(pointer p, const value_type& x)
{
new (p) value_type(x);
}
void destroy(pointer p)
{
p->~value_type();
}
HANDLE heap;
private:
void operator=(const winheap_allocator&);
};
template<>
class winheap_allocator<void>
{
typedef void value_type;
typedef void* pointer;
typedef const void* const_pointer;
template <class U>
struct rebind { typedef winheap_allocator<U> other; };
};
template <class T>
inline bool operator==(const winheap_allocator<T>& a,
const winheap_allocator<T>& b)
{
return a.heap == b.heap;
}
template <class T>
inline bool operator!=(const winheap_allocator<T>& a,
const winheap_allocator<T>& b)
{
return a.heap != b.heap;
}