在NSDictionary中存储C float数组

sam*_*b90 5 xcode opengl-es objective-c ios

我想存储c-float arrayNSDictionary以后使用.
我最初使用的NSArray是存储C数据但是NSArray为了减慢我的意图.

我使用以下代码将数组包装在NSDictionary中:

[self.m_morphPositions setObject:[NSValue valueWithBytes:&positionBuff objCType:@encode(float[(self.m_countVertices * 3)])] forKey:fourCC];
Run Code Online (Sandbox Code Playgroud)

并使用以下方法检索C-Float数组:

float posMorphs[(self.m_countVertices*3)];

NSValue *posValues = [self.m_morphPositions objectForKey:name];

[posValues getValue:&posMorphs];
Run Code Online (Sandbox Code Playgroud)

当我退出数组时,对于每个错误的索引,值都设置为0.0.

我怎样才能解决这个问题?

Sul*_*han 2

NSValue可能适用于标量值,而不是数组。在这种情况下,使用NSData应该会容易得多

NSData* data = [NSData dataWithBytes:&positionBuff length:(self.m_countVertices * 3 * sizeof(float))];
Run Code Online (Sandbox Code Playgroud)
[data getBytes:posMorphs length:(self.m_countVertices * 3 * sizeof(float))];
Run Code Online (Sandbox Code Playgroud)

另一种解决方案是在堆上分配数组并用于NSValue存储指针。