1e41f4b71Sopenharmony_ci# Memory
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## 概述
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci提供内存管理能力。
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci@Syscap SystemCapability.CommonLibrary.PurgeableMemory
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci**起始版本:**
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci10
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## 汇总
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci### 文件
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci| 名称 | 描述 | 
21e41f4b71Sopenharmony_ci| -------- | -------- |
22e41f4b71Sopenharmony_ci| [purgeable_memory.h](purgeable__memory_8h.md) | 声明从native层管理可丢弃内存的方法。<br>**引用文件**:<purgeable_memory/purgeable_memory.h> <br>**库**:libpurgeable_memory_ndk.z.so | 
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci### 类型定义
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| 名称 | 描述 | 
28e41f4b71Sopenharmony_ci| -------- | -------- |
29e41f4b71Sopenharmony_ci| [OH_PurgeableMemory](#oh_purgeablememory) | 用于定义OH_PurgeableMemory数据类型名称。 | 
30e41f4b71Sopenharmony_ci| (\*[OH_PurgeableMemory_ModifyFunc](#oh_purgeablememory_modifyfunc)) (void \*, size_t, void \*) | 用于重建可丢弃内存PurgeableMemory数据的方法。 | 
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci### 函数
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| 名称 | 描述 | 
36e41f4b71Sopenharmony_ci| -------- | -------- |
37e41f4b71Sopenharmony_ci| \*[OH_PurgeableMemory_Create](#oh_purgeablememory_create) (size_t size, [OH_PurgeableMemory_ModifyFunc](#oh_purgeablememory_modifyfunc) func, void \*funcPara) | 创建**PurgeableMemory**对象。 | 
38e41f4b71Sopenharmony_ci| [OH_PurgeableMemory_Destroy](#oh_purgeablememory_destroy) ([OH_PurgeableMemory](#oh_purgeablememory) \*purgObj) | 销毁**PurgeableMemory**对象。 | 
39e41f4b71Sopenharmony_ci| [OH_PurgeableMemory_BeginRead](#oh_purgeablememory_beginread) ([OH_PurgeableMemory](#oh_purgeablememory) \*purgObj) | 开始读取**PurgeableMemory**对象。检查PurgeableMemory是否被回收, 若被回收则调用重建方法进行重建 | 
40e41f4b71Sopenharmony_ci| [OH_PurgeableMemory_EndRead](#oh_purgeablememory_endread) ([OH_PurgeableMemory](#oh_purgeablememory) \*purgObj) | 结束读取**PurgeableMemory**对象。表示系统可回收该**PurgeableMemory**对象内存数据。 | 
41e41f4b71Sopenharmony_ci| [OH_PurgeableMemory_BeginWrite](#oh_purgeablememory_beginwrite) ([OH_PurgeableMemory](#oh_purgeablememory) \*purgObj) | 开始修改**PurgeableMemory**对象。检查PurgeableMemory是否被回收, 若被回收则调用重建方法进行重建 | 
42e41f4b71Sopenharmony_ci| [OH_PurgeableMemory_EndWrite](#oh_purgeablememory_endwrite) ([OH_PurgeableMemory](#oh_purgeablememory) \*purgObj) | 结束修改**PurgeableMemory**对象。表示系统可回收该**PurgeableMemory**对象内存数据。 | 
43e41f4b71Sopenharmony_ci| [OH_PurgeableMemory_GetContent](#oh_purgeablememory_getcontent) ([OH_PurgeableMemory](#oh_purgeablememory) \*purgObj) | 获取**PurgeableMemory**对象内存数据。 | 
44e41f4b71Sopenharmony_ci| [OH_PurgeableMemory_ContentSize](#oh_purgeablememory_contentsize) ([OH_PurgeableMemory](#oh_purgeablememory) \*purgObj) | 获取**PurgeableMemory**对象内存数据大小。 | 
45e41f4b71Sopenharmony_ci| [OH_PurgeableMemory_AppendModify](#oh_purgeablememory_appendmodify) ([OH_PurgeableMemory](#oh_purgeablememory) \*purgObj, [OH_PurgeableMemory_ModifyFunc](#oh_purgeablememory_modifyfunc) func, void \*funcPara) | 添加**PurgeableMemory**对象的修改方法。 | 
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci## 类型定义说明
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci### OH_PurgeableMemory
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci  
54e41f4b71Sopenharmony_ci```
55e41f4b71Sopenharmony_citypedef struct PurgMem OH_PurgeableMemory
56e41f4b71Sopenharmony_ci```
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**描述:**
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci用于定义OH_PurgeableMemory数据类型名称。
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci**起始版本:**
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci10
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci### OH_PurgeableMemory_ModifyFunc
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci  
70e41f4b71Sopenharmony_ci```
71e41f4b71Sopenharmony_citypedef bool(* OH_PurgeableMemory_ModifyFunc) (void *, size_t, void *)
72e41f4b71Sopenharmony_ci```
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**描述:**
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci用于重建可丢弃内存PurgeableMemory数据的方法。
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**参数:**
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci| 名称 | 描述 | 
81e41f4b71Sopenharmony_ci| -------- | -------- |
82e41f4b71Sopenharmony_ci| void \* | 指向PurgeableMemory内容的内存地址。 | 
83e41f4b71Sopenharmony_ci| size_t | 重建内容的大小。 | 
84e41f4b71Sopenharmony_ci| void \* | 重建参数。 | 
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**返回:**
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci操作成功则返回成功;如果操作失败,则返回失败。
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**起始版本:**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci10
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci## 函数说明
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci### OH_PurgeableMemory_AppendModify()
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci  
101e41f4b71Sopenharmony_ci```
102e41f4b71Sopenharmony_cibool OH_PurgeableMemory_AppendModify (OH_PurgeableMemory * purgObj, OH_PurgeableMemory_ModifyFunc func, void * funcPara )
103e41f4b71Sopenharmony_ci```
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci**描述:**
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci添加**PurgeableMemory**对象的修改方法。
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci**参数:**
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci| 名称 | 描述 | 
112e41f4b71Sopenharmony_ci| -------- | -------- |
113e41f4b71Sopenharmony_ci| purgObj | 待添加修改方法的PurgeableMemory对象。 | 
114e41f4b71Sopenharmony_ci| func | 关于数据修改方法的函数指针,用于PurgeableMemory内存数据重建后进一步修改。 | 
115e41f4b71Sopenharmony_ci| funcPara | 修改方法的参数。 | 
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci**返回:**
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci如果添加成功则返回成功,否则返回失败。
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**起始版本:**
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci10
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci### OH_PurgeableMemory_BeginRead()
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci  
129e41f4b71Sopenharmony_ci```
130e41f4b71Sopenharmony_cibool OH_PurgeableMemory_BeginRead (OH_PurgeableMemory * purgObj)
131e41f4b71Sopenharmony_ci```
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci**描述:**
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci开始读取**PurgeableMemory**对象。检查PurgeableMemory是否被回收, 若被回收则调用重建方法进行重建
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci**参数:**
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci| 名称 | 描述 | 
140e41f4b71Sopenharmony_ci| -------- | -------- |
141e41f4b71Sopenharmony_ci| purgObj | 待读取的PurgeableMemory对象。 | 
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci**返回:**
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci如果PurgeableMemory内存数据准备好则返回成功; 如果PurgeableMemory内存数据已被回收且重建失败则返回失败。
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci**起始版本:**
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci10
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci### OH_PurgeableMemory_BeginWrite()
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci  
155e41f4b71Sopenharmony_ci```
156e41f4b71Sopenharmony_cibool OH_PurgeableMemory_BeginWrite (OH_PurgeableMemory * purgObj)
157e41f4b71Sopenharmony_ci```
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci**描述:**
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci开始修改**PurgeableMemory**对象。检查PurgeableMemory是否被回收, 若被回收则调用重建方法进行重建
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci**参数:**
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci| 名称 | 描述 | 
166e41f4b71Sopenharmony_ci| -------- | -------- |
167e41f4b71Sopenharmony_ci| purgObj | 待修改的PurgeableMemory对象。 | 
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci**返回:**
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci如果PurgeableMemory内存数据准备好则返回成功; 如果PurgeableMemory内存数据已被回收且重建失败则返回失败。
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci**起始版本:**
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci10
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci### OH_PurgeableMemory_ContentSize()
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci  
181e41f4b71Sopenharmony_ci```
182e41f4b71Sopenharmony_cisize_t OH_PurgeableMemory_ContentSize (OH_PurgeableMemory * purgObj)
183e41f4b71Sopenharmony_ci```
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci**描述:**
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci获取**PurgeableMemory**对象内存数据大小。
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci**参数:**
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci| 名称 | 描述 | 
192e41f4b71Sopenharmony_ci| -------- | -------- |
193e41f4b71Sopenharmony_ci| purgObj | 待读取内存数据的PurgeableMemory对象。 | 
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci**返回:**
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci返回PurgeableMemory对象内存数据大小。
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_ci**起始版本:**
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ci10
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci### OH_PurgeableMemory_Create()
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci  
207e41f4b71Sopenharmony_ci```
208e41f4b71Sopenharmony_ciOH_PurgeableMemory* OH_PurgeableMemory_Create (size_t size, OH_PurgeableMemory_ModifyFunc func, void * funcPara )
209e41f4b71Sopenharmony_ci```
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ci**描述:**
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci创建**PurgeableMemory**对象。
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci**参数:**
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci| 名称 | 描述 | 
218e41f4b71Sopenharmony_ci| -------- | -------- |
219e41f4b71Sopenharmony_ci| size | PurgeableMemory对象大小。 | 
220e41f4b71Sopenharmony_ci| func | 关于重建方法的函数指针,用于恢复被回收的PurgeableMemory内存数据。 | 
221e41f4b71Sopenharmony_ci| funcPara | 用于重建的参数。 | 
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci**返回:**
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci返回PurgeableMemory对象。
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci**起始版本:**
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci10
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci### OH_PurgeableMemory_Destroy()
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci  
235e41f4b71Sopenharmony_ci```
236e41f4b71Sopenharmony_cibool OH_PurgeableMemory_Destroy (OH_PurgeableMemory * purgObj)
237e41f4b71Sopenharmony_ci```
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_ci**描述:**
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ci销毁**PurgeableMemory**对象。
242e41f4b71Sopenharmony_ci
243e41f4b71Sopenharmony_ci**参数:**
244e41f4b71Sopenharmony_ci
245e41f4b71Sopenharmony_ci| 名称 | 描述 | 
246e41f4b71Sopenharmony_ci| -------- | -------- |
247e41f4b71Sopenharmony_ci| purgObj | 需要销毁的PurgeableMemory对象。 | 
248e41f4b71Sopenharmony_ci
249e41f4b71Sopenharmony_ci**返回:**
250e41f4b71Sopenharmony_ci
251e41f4b71Sopenharmony_ci操作成功则返回成功;如果操作失败,则返回失败。如果purgObj为空则返回失败; 如果返回成功,purgObj会置空避免Use-After-Free。
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_ci**起始版本:**
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci10
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci### OH_PurgeableMemory_EndRead()
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ci  
261e41f4b71Sopenharmony_ci```
262e41f4b71Sopenharmony_civoid OH_PurgeableMemory_EndRead (OH_PurgeableMemory * purgObj)
263e41f4b71Sopenharmony_ci```
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ci**描述:**
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ci结束读取**PurgeableMemory**对象。表示系统可回收该**PurgeableMemory**对象内存数据。
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci**参数:**
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci| 名称 | 描述 | 
272e41f4b71Sopenharmony_ci| -------- | -------- |
273e41f4b71Sopenharmony_ci| purgObj | 结束读取的PurgeableMemory对象。 | 
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci**起始版本:**
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci10
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ci### OH_PurgeableMemory_EndWrite()
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci  
283e41f4b71Sopenharmony_ci```
284e41f4b71Sopenharmony_civoid OH_PurgeableMemory_EndWrite (OH_PurgeableMemory * purgObj)
285e41f4b71Sopenharmony_ci```
286e41f4b71Sopenharmony_ci
287e41f4b71Sopenharmony_ci**描述:**
288e41f4b71Sopenharmony_ci
289e41f4b71Sopenharmony_ci结束修改**PurgeableMemory**对象。表示系统可回收该**PurgeableMemory**对象内存数据。
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ci**参数:**
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci| 名称 | 描述 | 
294e41f4b71Sopenharmony_ci| -------- | -------- |
295e41f4b71Sopenharmony_ci| purgObj | 结束修改的**PurgeableMemory**对象。 | 
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ci**起始版本:**
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci10
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci### OH_PurgeableMemory_GetContent()
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci  
305e41f4b71Sopenharmony_ci```
306e41f4b71Sopenharmony_civoid* OH_PurgeableMemory_GetContent (OH_PurgeableMemory * purgObj)
307e41f4b71Sopenharmony_ci```
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci**描述:**
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_ci获取**PurgeableMemory**对象内存数据。
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ci**参数:**
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci| 名称 | 描述 | 
316e41f4b71Sopenharmony_ci| -------- | -------- |
317e41f4b71Sopenharmony_ci| purgObj | 待读取内存数据的PurgeableMemory对象。 | 
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci**返回:**
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_ci返回PurgeableMemory对象内存地址。
322e41f4b71Sopenharmony_ci
323e41f4b71Sopenharmony_ci**起始版本:**
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ci10
326