Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The idea would just be to add a pointer to an array of AEMesh structures to your class, and then maintain the array as necessary. Following is a little (untested) code that uses malloc() to create such an array and realloc() to resize it. I'm growing the array 10 meshes at a time:</p> <pre><code>@interface MyClass : NSObject { int meshCount; AEMesh *meshes; } @end @implementation MyClass -(id)init { if ((self = [super init])) { meshCount = 0; meshes = malloc(sizeof(AEMesh)*10); } return self; } -(void)addMesh:(AEMesh)mesh { if (meshCount % 10 = 0) { meshCount = realloc(sizeof(AEMesh) * (meshCount + 10)); } if (meshCount != nil) { meshes[meshCount] = mesh; meshCount++; } } @end </code></pre> <p>It might be worthwhile to factor the array management into it's own Objective-C class, much as Brian Coleman's answer uses std::vector to manage the meshes. That way, you could use it for C arrays of any type, not just AEMesh.</p> <blockquote> <p>From the information Ive gathered, using malloc might work, but this isn't creating a standard c-array I can pass in to OpenGL ES, instead its more of a pseudo-c-array that works like a c-array?</p> </blockquote> <p>A C array is nothing more than a series of objects ("objects" used here in the C sense of contiguous memory, not the OO sense) in memory. You can create one by declaring it on the stack:</p> <pre><code>int foo[10]; // array of 10 ints </code></pre> <p>or dynamically on the heap:</p> <pre><code>int foo[] = malloc(sizeof(int)*10); // array of 10 ints, not on the stack int *bar = malloc(sizeof(int)*10); // another way to write the same thing </code></pre> <p>Don't forget to use free() to deallocate any blocks of memory you've created with malloc(), realloc(), calloc(), etc. when you're done with them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload