Random pointer issues
Hmmm, I thought about using an NSArray or NSMutable array, however since the size is never changing I figured that the use of a mutable array was silly. The reason I shyed away from using an NSArray is because for some reason I see it all the time for use with NSStrings but not with much else. I figured that the basic C array would suffice and it looked to me that the use of an NSArray might actually slow the exicution down. If I'm wrong about anyof that please let me know.
Kaamoss Wrote:Hmmm, I thought about using an NSArray or NSMutable array, however since the size is never changing I figured that the use of a mutable array was silly.
You're shuffling the deck, so you need to use an NSMutableArray because an NSArray doesn't let you alter its list of objects. In other words, if you use an NSArray, you can't re-order the array's objects, resize the array, or swap-out one of its objects for a different object.
NSArrays and NSMutableArrays are actually quite lightweight and fast. Give them a try... you'll see
Also, if you insist on using a plain C array, use malloc(sizeof(Card *) * 52) inside Deck's init method. Then use free() inside Deck's dealloc method. This will ensure that each Deck instance gets its own array.
Possibly Related Threads...
|memory pointer tricks?||Toontingy||2||3,680||
Mar 31, 2009 02:35 AM
Last Post: Ingemar
|pointer cleanup questions||kendric||7||3,857||
Mar 29, 2009 07:48 PM
Last Post: kendric
|pointer or not?||kensuguro||17||7,225||
Aug 15, 2007 04:12 PM
Last Post: AnotherJake
|My AnimationManager didn't like being a pointer.||milkfilk||6||3,454||
Mar 24, 2007 10:03 PM
Last Post: unknown
|Pointer-related woes (C/C++)||sealfin||2||2,299||
Jan 18, 2006 01:22 PM
Last Post: sealfin