Ios 在目标C中动态设置C-Struct数组的大小?

Ios 在目标C中动态设置C-Struct数组的大小?,ios,objective-c,c,opengl-es,struct,Ios,Objective C,C,Opengl Es,Struct,在我的OpenGL ES 2.0项目中,我在初始化Vertice和Indice c-Struct数组的对象中有以下代码: Vertex Vertices [] = { {{0.0, 0.0, 0}, {0.9, 0.9, 0.9, 1}}, {{0.0 , 0.0 , 0}, {0.9, 0.9, 0.9, 1}}, {{0.0, 0.0, 0}, {0.9, 0.9, 0.9, 1}}, {{0.0, 0.0, 0}, {0.9, 0.9, 0.9, 1}}, }; static GLuby

在我的OpenGL ES 2.0项目中,我在初始化Vertice和Indice c-Struct数组的对象中有以下代码:

Vertex Vertices [] = {
{{0.0, 0.0, 0}, {0.9, 0.9, 0.9, 1}},
{{0.0 , 0.0 , 0}, {0.9, 0.9, 0.9, 1}},
{{0.0, 0.0, 0}, {0.9, 0.9, 0.9, 1}},
{{0.0, 0.0, 0}, {0.9, 0.9, 0.9, 1}},
};

static GLubyte Indices []= {
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
};
由于我要渲染不同的多边形,我希望能够从调用类中动态设置顶点和索引。我试着把:

Vertex Vertices [] = {
};

static GLubyte Indices []= {
};
这是我设置verticeArray顶点的地方(这是从调用类设置的数组)


但是,我认为这会导致崩溃,因为数组从未分配过alloced/内存分配。有人能建议我如何做到这一点吗?

你必须这样做

    int *arr = (int *)malloc(5*sizeof(int));
可以用int替换结构类型,即

typedef struct vertex {
  int x[3];
  float y[4]; 
} vertex;

int count = 10;

vertex *Vertices = (vertex *)malloc(count * sizeof(vertex));
完成后,确实需要释放内存

free(Vertices);
Vertices = NULL;

使用指针怎么样?沿着顶点线的一些东西*VerticesPtr;顶点[]={….};VerticesPtr=&顶点;因此,我在标题中声明如下:顶点*顶点;然后:int数组=4;顶点=(顶点*)malloc(数组*sizeof(顶点));正确的?
free(Vertices);
Vertices = NULL;