forked from microsoft/SEAL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memorypoolhandle.cpp
135 lines (108 loc) · 3.48 KB
/
memorypoolhandle.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// SEALNet
#include "seal/c/memorypoolhandle.h"
#include "seal/c/utilities.h"
// SEAL
#include "seal/memorymanager.h"
using namespace std;
using namespace seal;
using namespace seal::c;
SEAL_C_FUNC MemoryPoolHandle_Create1(void **handle)
{
IfNullRet(handle, E_POINTER);
MemoryPoolHandle *handleptr = new MemoryPoolHandle();
*handle = handleptr;
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_Create2(void *otherptr, void **handle)
{
MemoryPoolHandle *other = FromVoid<MemoryPoolHandle>(otherptr);
IfNullRet(other, E_POINTER);
IfNullRet(handle, E_POINTER);
MemoryPoolHandle *handleptr = new MemoryPoolHandle(*other);
*handle = handleptr;
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_Destroy(void *thisptr)
{
MemoryPoolHandle *handle = FromVoid<MemoryPoolHandle>(thisptr);
IfNullRet(handle, E_POINTER);
delete handle;
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_Set(void *thisptr, void *assignptr)
{
MemoryPoolHandle *handle = FromVoid<MemoryPoolHandle>(thisptr);
IfNullRet(handle, E_POINTER);
MemoryPoolHandle *assign = FromVoid<MemoryPoolHandle>(assignptr);
IfNullRet(assign, E_POINTER);
*handle = *assign;
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_Global(void **handle)
{
IfNullRet(handle, E_POINTER);
MemoryPoolHandle global = MemoryPoolHandle::Global();
MemoryPoolHandle *handleptr = new MemoryPoolHandle(move(global));
*handle = handleptr;
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_ThreadLocal(void **handle)
{
IfNullRet(handle, E_POINTER);
MemoryPoolHandle threadlocal = MemoryPoolHandle::ThreadLocal();
MemoryPoolHandle *handleptr = new MemoryPoolHandle(move(threadlocal));
*handle = handleptr;
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_New(bool clear_on_destruction, void **handle)
{
IfNullRet(handle, E_POINTER);
MemoryPoolHandle newhandle = MemoryPoolHandle::New(clear_on_destruction);
MemoryPoolHandle *handleptr = new MemoryPoolHandle(move(newhandle));
*handle = handleptr;
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_PoolCount(void *thisptr, uint64_t *count)
{
MemoryPoolHandle *pool = FromVoid<MemoryPoolHandle>(thisptr);
IfNullRet(pool, E_POINTER);
IfNullRet(count, E_POINTER);
*count = pool->pool_count();
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_AllocByteCount(void *thisptr, uint64_t *count)
{
MemoryPoolHandle *pool = FromVoid<MemoryPoolHandle>(thisptr);
IfNullRet(pool, E_POINTER);
IfNullRet(count, E_POINTER);
*count = pool->alloc_byte_count();
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_UseCount(void *thisptr, long *count)
{
MemoryPoolHandle *pool = FromVoid<MemoryPoolHandle>(thisptr);
IfNullRet(pool, E_POINTER);
IfNullRet(count, E_POINTER);
*count = pool->use_count();
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_IsInitialized(void *thisptr, bool *result)
{
MemoryPoolHandle *pool = FromVoid<MemoryPoolHandle>(thisptr);
IfNullRet(pool, E_POINTER);
IfNullRet(result, E_POINTER);
*result = (bool)(*pool);
return S_OK;
}
SEAL_C_FUNC MemoryPoolHandle_Equals(void *thisptr, void *otherptr, bool *result)
{
MemoryPoolHandle *pool = FromVoid<MemoryPoolHandle>(thisptr);
IfNullRet(pool, E_POINTER);
MemoryPoolHandle *other = FromVoid<MemoryPoolHandle>(otherptr);
IfNullRet(other, E_POINTER);
IfNullRet(result, E_POINTER);
*result = (*pool == *other);
return S_OK;
}