ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/Deliantra-Client/salloc.h
Revision: 1.2
Committed: Mon Nov 19 01:37:28 2018 UTC (5 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +5 -5 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 root 1.2 template <class U>
16     bool operator == (const slice_allocator<U> &) noexcept { return true ; }
17     template <class U>
18     bool operator != (const slice_allocator<U> &) noexcept { return false; }
19    
20 root 1.1 Tp *allocate (std::size_t n)
21     {
22     return (Tp *)g_slice_alloc (n * sizeof (Tp));
23     }
24    
25     void deallocate (Tp *p, std::size_t n) noexcept
26     {
27     g_slice_free1 (n * sizeof (Tp), p);
28     }
29     };
30    
31     #endif