2011-12-15 12 views
1

私は以下のコードをアプリケーション内でmallocメモリをstructオブジェクトに持っています。このメソッドは、新しいVector3Dオブジェクトのメモリをmallocingするたびに、コード内で何回か呼び出されます。構造体へのポインタの配列への格納? iPhone

私がしたいことは、mallocされたShapeClassオブジェクト(C構造体)へのポインタを取得して、後で各オブジェクトをdeallocメソッドで解放できるようにすることです。

誰も私にどのようにポインタを配列に追加できますか?

ありがとうございます。

vectorCount = [floatArray.array count]/3; 
     ShapeClass *vectorArray = malloc(sizeof(Vector3D) * vectorCount); 
     for (int i=0; i<vectorCount; i++) { 
      vectorArray[i].x = [[floatArray.array objectAtIndex:(i*3)] floatValue]; 
      vectorArray[i].y = [[floatArray.array objectAtIndex:(i*3)+1] floatValue]; 
      vectorArray[i].z = [[floatArray.array objectAtIndex:(i*3)+2] floatValue]; 
     } 
     return vectorArray; 
// I WANT TO INSERT SOMETHING HERE TO CAPTURE THE POINTER TO vectorArray - E.G ADD IT TO AN ARRAY ? 
    } 
} 
return NULL; 
} 

答えて

1

[NSValue valueWithPointer:]を使用してコンテナクラスに格納します。

NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 
SomeObject *object = [[SomeObject alloc] init]; 

//Store the pointer to object 
[dictionary setValue:[NSValue valueWithPointer:object] forKey:@"object"];