当前位置:网站首页>[openvx] VX for basic use of objects_ array
[openvx] VX for basic use of objects_ array
2022-07-23 08:43:00 【zhy29563】
Catalog
1. Test code
#include <iostream>
#include <VX/vx.h>
// Array Is a strongly typed container . The container provides random access at the same speed .
// It uses value semantics on its own elements and saves copies of data . The following is an array traversal
void print_array(vx_array array, char* message)
{
std::cout << "===============================" << std::endl;
std::cout << message << std::endl;
vx_size num;
vxQueryArray(array, VX_ARRAY_NUMITEMS, &num, sizeof(num));
vx_enum type;
vxQueryArray(array, VX_ARRAY_ITEMTYPE, &type, sizeof(type));
vx_size capacity;
vxQueryArray(array, VX_ARRAY_CAPACITY, &capacity, sizeof(capacity));
vx_size item_size;
vxQueryArray(array, VX_ARRAY_ITEMSIZE, &item_size, sizeof(item_size));
std::cout << "num : " << num << std::endl;
std::cout << "type : " << type << std::endl;
std::cout << "capacity : " << capacity << std::endl;
std::cout << "item_size: " << item_size << std::endl;
vx_map_id map_id;
vx_size size;
void *ptr;
vxMapArrayRange(array, 0, 5, &map_id, &size, &ptr, VX_READ_ONLY, VX_MEMORY_TYPE_HOST, VX_NOGAP_X);
std::cout << "ptr : " << ptr << std::endl;
for (size_t i = 0; i < num; i++)
{
//std::cout << "index: " << i << ", value: " << (int)((uint8_t*)ptr)[i] << std::endl;
std::cout << "index: " << i << ", value: " << (int)vxArrayItem(uint8_t, ptr, i, item_size) << std::endl;
}
vxUnmapArrayRange(array, map_id);
}
int main(int argc, char *argv[])
{
vx_status status = VX_SUCCESS;
vx_context context = vxCreateContext();
// Create array , At this time, the array has only capacity , No data
vx_array array = vxCreateArray(context, (vx_enum)VX_TYPE_INT8, 5);
print_array(array, (char*)"create");
// Additive elements
uint8_t uint8_new_arr[]{
5, 6, 7, 8, 9};
vxAddArrayItems(array, 5, uint8_new_arr, sizeof(uint8_t));
print_array(array, (char*)"add item");
// Update elements
uint8_t uint8_init_arr[]{
0, 1, 2, 3, 4};
vxCopyArrayRange(array, 0, 5, sizeof(uint8_t), uint8_init_arr, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST);
print_array(array, (char*)"update item");
// Add elements again , By default , This function does not reallocate memory . If before adding elements , The array is full , Or there is not enough space left to store new data , return VX_FAILURE
uint8_t uint8_new_arr_again[]{
5, 6, 7, 8, 9};
status = vxAddArrayItems(array, 5, uint8_new_arr_again, sizeof(uint8_t));
std::cout << "vxAddArrayItems: " << status << std::endl;
print_array(array, (char*)"add items again");
// Truncated array , Reallocate data memory . The truncated data is a random value
status = vxTruncateArray(array, 3);
std::cout << "vxTruncateArray: " << status << std::endl;
print_array(array, (char*)"truncate array");
vxReleaseArray(&array);
vxReleaseContext(&context);
return EXIT_SUCCESS;
}
2. Running results
===============================
create
num : 0
type : 2
capacity : 5
item_size: 1
ptr : 0x7f12a99a53d6
===============================
add item
num : 5
type : 2
capacity : 5
item_size: 1
ptr : 0x55eba811e770
index: 0, value: 5
index: 1, value: 6
index: 2, value: 7
index: 3, value: 8
index: 4, value: 9
===============================
update item
num : 5
type : 2
capacity : 5
item_size: 1
ptr : 0x55eba811e770
index: 0, value: 0
index: 1, value: 1
index: 2, value: 2
index: 3, value: 3
index: 4, value: 4
vxAddArrayItems: -1
===============================
add items again
num : 5
type : 2
capacity : 5
item_size: 1
ptr : 0x55eba811e770
index: 0, value: 0
index: 1, value: 1
index: 2, value: 2
index: 3, value: 3
index: 4, value: 4
vxTruncateArray: 0
===============================
truncate array
num : 3
type : 2
capacity : 5
item_size: 1
ptr : 0x55eba78088b0
index: 0, value: 243
index: 1, value: 15
index: 2, value: 30
边栏推荐
猜你喜欢

Arcgis js api二次开发——加载国家天地图

Talking about -- network security architecture design (II)

DP+回溯分割回文串的系列问题

一文读懂Elephant Swap的LaaS方案的优势之处
[email protected]、$?、env看所有的全局变量值、set看所有变量"/>Shell变量、系统预定义变量$HOME、$PWD、$SHELL、$USER、自定义变量、特殊变量$n、$#、$*、[email protected]、$?、env看所有的全局变量值、set看所有变量
![[arxiv2022] grouptransnet: Group transformer Network for RGB - D Salient Object Detection](/img/be/534f92578f0d825f9b565c1785af18.png)
[arxiv2022] grouptransnet: Group transformer Network for RGB - D Salient Object Detection
[email protected], "/>Shell variables, system predefined variables $home, $pwd, $shell, $user, custom variables, special variables $n, $, $*, [email protected],

Initializing, cleaning up and const decorating member functions of constructors

Redis速成

08 爬虫项目
随机推荐
Node definition and traversal of binary tree~
Dynamic programming and Markov characteristic optimal scheduling strategy (matlab complete code implementation)
【C语言】文件操作
浅谈——网络安全架构设计(四)
浅谈——网路安全架构设计(一)
SSH password free login configuration
【arXiv2022】GroupTransNet: Group Transformer Network for RGB-D Salient Object Detection
Binary tree expression evaluation~
【arXiv2022】GroupTransNet: Group Transformer Network for RGB-D Salient Object Detection
国债逆回购安全吗 如何网上开户?
Redistemplate pipeline use
【OPENVX】对象基本使用之vx_reference
Intel raid simulator Download
What type of die cutting machine can be used for paper?
1.学会看懂网页
What is the value of the new meta universe layout "primitive Cube" of "crazy diners"?
uva11389
【arXiv2022】GroupTransNet: Group Transformer Network for RGB-D Salient Object Detection
【GNN报告】香港科技大学李佳:图异常检测再思考—我们究竟需要怎样的图神经网络?
Android security topics -so reverse entry and dynamic debugging using IDA