File: largepage.hpp

package info (click to toggle)
unrar-nonfree 1%3A7.1.8-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 1,952 kB
  • sloc: cpp: 26,394; makefile: 712; sh: 11
file content (54 lines) | stat: -rw-r--r-- 1,301 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _RAR_LARGEPAGE_
#define _RAR_LARGEPAGE_

class LargePageAlloc
{
  private:
    static constexpr const wchar *LOCKMEM_SWITCH=L"isetup_privilege_lockmem";

    void* new_large(size_t Size);
    bool delete_large(void *Addr);
#ifdef _WIN_ALL
    std::vector<void*> LargeAlloc;
    SIZE_T PageSize;
#endif
    bool UseLargePages;
  public:
    LargePageAlloc();
    void AllowLargePages(bool Allow);
    static bool IsPrivilegeAssigned();
    static bool AssignPrivilege();
    static bool AssignPrivilegeBySid(const std::wstring &Sid);
    static bool AssignConfirmation();

    static bool ProcessSwitch(CommandData *Cmd,const wchar *Switch)
    {
      if (Switch[0]==LOCKMEM_SWITCH[0])
      {
        size_t Length=wcslen(LOCKMEM_SWITCH);
        if (wcsncmp(Switch,LOCKMEM_SWITCH,Length)==0)
        {
          LargePageAlloc::AssignPrivilegeBySid(Switch+Length);
          return true;
        }
      }
      return false;
    }

    template <class T> T* new_l(size_t Size,bool Clear=false)
    {
      T *Allocated=(T*)new_large(Size*sizeof(T));
      if (Allocated==nullptr)
        Allocated=Clear ? new T[Size]{} : new T[Size];
      return Allocated;
    }

    template <class T> void delete_l(T *Addr)
    {
      if (!delete_large(Addr))
        delete[] Addr;
    }
};


#endif