objective c - Accessing my malloc'd 2d array with [x][y] -
I used a member variable to define a 2D array limit instead of #defines to update a class I was doing this:
#define kWidth3 #define kHeight 100 NSUInteger field [kWidth] [kHeight]; There are now wythth and KHite Eyes. I switch to the malloc conference, because I do not see any other option because the limit can now change The problem is that I have two [] ([] []) Can not reach the array. See my inline comment I'm sure I have correctly malloc'd I have done many times earlier and under iOS. Why can not I reach this way?
self.kFieldsHeight = 100; Self.kFieldsWidth = 3; NSUntegaeer ** Field = (NSUNTEER **) Molok (Siezf (NSUNTEGER) * Self. Keffield Hight * Self. KeffieldSwidth); Memet (Field, 0x FF, Self Keffieldswidth * Self. KeffieldSite * Siezf (NSUNTEGER)); Now with the ////LLDB, I can see the array in one dimension // p field [0] / 0xFFFFFFFF // p field [29] / 0xFFFFFFFF // p field [300] / / 0xGARBAGE //// "Failed with error: The straight can not be dematerialized: no overall type could be read from the target: gdb remote returned a error: E08" // p field [0] [0] Returning]
// Therefore my code fails in NSUInteger i = areas [0] [0]; What's the deal?
Edit: (More details) I have also tried to mauloki like this:
fields = (nsuentengar **) maulok (size (nsuentenga * ) * Self. KeffieldHight); If (field) {for (int i = 0; i and lieutenant; self.keyfield heit; i ++) {field [i] = (nsuentengar) * molok (ssef (nsuinteng) * self. Kefildswitch); }} Edit: (even more details). I swap the width and height with the same result:
fields = (ms) (sizeof (NSUInteger *) * self.kFieldsWidth); If (field) {for (int i = 0; i & lt; self.keffswitch; i ++) {field [i] = molok (ssf (nsuinteng) * self. Kefildsahit); }}
You have to:
NSUntenger ** Field = Molec (self. Keffield Hight * size (NSUNTEGER *)); For (Int i = 0; I and Lt; self. Keffield Highight; I ++) {Field [I] = Molok (Siezf (NSUNTEGER) * Self. KeffieldSwidth); Memset (field, 0x FF, self keyfieldswidth * sizf (NSUNTEGER)); } But it is not that most people do jobs. Most developers use a large array instead of 2d arrays and try to index it themselves. Like this: NSUInteger * fields = malloc (self.kFieldsHyight * self.kFieldsHyight * sizeof (NSUInteger)); Field [h * width = wa] = pixel_value;
Comments
Post a Comment