op_prg_list_free()
摘要
释放指定列表的内容,释放相关内存资源以供其他用途。
注意: 该内核过程是一个仅为向后兼容而保留的宏调用。新代码应使用 prg_list_free()。
语法
op_prg_list_free (list_ptr)
| 参数 | 类型 | 说明 |
|---|---|---|
ist_ptr |
List* |
指向目标列表的指针 [列表指针可以从多个内核过程获得:空列表可由 op_prg_list_create() 获得;表示文件内容的列表可由 op_prg_gdf_read() 获得;列表可由用户代码静态分配并通过 op_prg_list_init() 初始化。]。 |
返回类型
void
无返回值。
示例
/* open and read in the contents of a GDF */
list_ptr = op_prg_gdf_read (gdf_file_name);
/* loop through the contents of the GDF contents list, */
/* printing each line */
list_size = op_prg_list_size (list_ptr);
for (i = 0; i < list_size; i++)
printf ("line %d: [%s]\n", i, (char*) op_prg_list_access (list_ptr, i));
/* deallocate the elements on the list */
op_prg_list_free (list_ptr);
/* deallocate the list itself */
op_prg_mem_free (list_ptr);
详情
通过 op_prg_list_free() 释放列表的内容并不会释放列表本身(列表由一个小型数据结构表示)。相反,列表会被初始化,可以重新使用。如果不再需要列表本身,可以使用内核过程 op_prg_mem_free() 将其释放。
该内核过程只能释放列表内通过仿真内核已知方法分配的元素。例如,直接通过内存分配器 malloc() 分配的元素不会被释放,并且会发出错误消息。仿真内核已知的方法包括通过 op_prg_mem_alloc()、op_prg_gdf_read()、op_prg_str_decomp() 和 op_prg_list_elems_copy() 分配的内存。
注意: 该内核过程不是 MT 安全的,如 “Multi-Threading Safety“ 第 11 页所述。对共享列表的访问必须由外部串行化。
用途
提供一种机制,当列表中的所有元素不再有用时将其全部释放,以回收其内存。这些元素必须是通过已知的仿真内核接口分配的。
错误
- 程序中止:段错误。(由于列表中存在未知内存类型或非法元素指针)
- 程序中止:总线错误。(由于列表中存在未知内存类型或非法元素指针)
- 诊断错误:无法释放未知内存类型。
参考
- 使用内核过程 op_prg_mem_free() 释放不再有用的列表(在其元素已被释放之后)
- 使用内核过程 op_prg_list_create() 分配一个新的空列表
- 使用内核过程 op_prg_list_init() 准备一个新的空列表,或将现有列表重置为空状态