DZAUnsafeMutableArray 0.2.1

DZAUnsafeMutableArray 0.2.1

测试测试
语言 Obj-CObjective C
许可证 MIT
发布最后发布2017年6月

Davide Di Stefano 维护。




这是用于什么的

此类是围绕 c 自动增长指针数组的 Objective-C 包装器。

我构建了这个库,因为我正在重写 RouletteBetter,并且我想找到一种方法来对向量进行大量的统计分析。为此,我们可以使用 iOS Accelerate 框架来“执行大规模数学计算和图像计算,优化高性能”。不幸的是,Accelerate 框架需要基本 c 指针数组作为输入/输出参数,所以我们不能使用 NSMutableArray 或高级 NSObjects。

使用这个包装库,我们可以轻松创建和操作 c 指针数组作为一个高级对象,并在需要的时候,访问低级指针属性(例如将其传递给 Accelerate 框架的 c 函数)。

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

示例用法

// create and fill the array as an high level object
DZAUnsafeMutableArray * unsafeArray = [[DZAUnsafeMutableArray alloc] initWithCapacity:10];
for (int i = 0; i < 10; i++)
{
    [unsafeArray addInt:i];
}

// access an element of the array
int element = [unsafeArray intAtIndex:3];
// remove the last object
[unsafeArray removeLastObject];
// shrink the array to the new size
[unsafeArray shrinkToSize:5];
// low-level access to the c pointer array
int * pointer = unsafeArray.intUnsafePointer;
// iterate all the items and manually sum a scalar
for (int i = 0; i < unsafeArray1.count; i++, pointer++)
{
    *pointer += SCALAR;
}
// use the c pointer array with Accelerate framework:
// sums a scalar to the entire vector
int scalar = 3;
vDSP_vsaddi(unsafeArray.intUnsafePointer, 1, &scalar, unsafeArray.intUnsafePointer, 1, unsafeArray.count);

包含了一个小的基准应用程序

Benchmark with small array Benchmark with big array

要求

安装

DZAUnsafeMutableArray 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod "DZAUnsafeMutableArray"

作者

Davide Di Stefano,[email protected]

许可证

DZAUnsafeMutableArray 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。