views:

91

answers:

1

There's this instance variable in my objective-c class:

ALuint source;

I need to have an mutable array of OpenAL Sources, so in this case probably I need a mutable C-array.

But how would I create one? There are many questions regarding that:

1) How to create an mutable C-array?

2) How to add something to that mutable C-array?

3) How to remove something from that mutable C-array?

4) What memory management pitfalls must I be aware of? Must i free() it in my -dealloc method?

+3  A: 

I’d keep things simple. ALuint is some kind of int, so that you can easily wrap it using NSNumber and stick it in an ordinary NSMutableArray:

ALuint bar = …;
NSMutableArray *foo = [NSMutableArray array];
[foo addObject:[NSNumber numberWithInt:bar]];

// and later
ALuint source = [[foo lastObject] intValue];
zoul
good point... however, would be good to know how to do something in c, when performance matters. allocacting objective-c objects is very heavy.
dontWatchMyProfile
It is not. It can make a difference when you’re writing a particle engine with dozens of thousands of particles to be recalculated at 50 fps. In the remaining 99.9 % of cases the bottleneck is going to be elsewhere.
zoul