ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/salloc.h
Revision: 1.1
Committed: Mon Nov 19 01:23:01 2018 UTC (5 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef SALLOC_H
2 #define SALLOC_H
3
4 // a C++ allocator trait class based on the slice allocator
5 template<typename Tp>
6 struct slice_allocator
7 {
8 typedef Tp value_type;
9
10 slice_allocator () noexcept { }
11 template<typename Tp2>
12 slice_allocator (const slice_allocator<Tp2> &) noexcept { }
13 ~slice_allocator () noexcept { }
14
15 Tp *allocate (std::size_t n)
16 {
17 return (Tp *)g_slice_alloc (n * sizeof (Tp));
18 }
19
20 void deallocate (Tp *p, std::size_t n) noexcept
21 {
22 g_slice_free1 (n * sizeof (Tp), p);
23 }
24 };
25
26 template <class T, class U>
27 bool operator == (const slice_allocator<T>&, const slice_allocator<U>&) noexcept { return true ; }
28 template <class T, class U>
29 bool operator != (const slice_allocator<T>&, const slice_allocator<U>&) noexcept { return false; }
30
31 #endif