How to make an mutable C array for this data type?
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.
开发者_StackOverflow中文版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?
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];
精彩评论