The hard-coded 3 was there because I thought I needed
a maximum of 3 chars for each row(including the null
terminator), not because of the size of Char. I'm not
sure I needed the space at the front of the
single-char numbers, but I thought it would be easier
if they were all the same width. I was envisioning the
rows of the array to be something like this (this is
the whole array, with each row delimited by the
commas):

' 1\0', ' 2\0'...'10\0'

Since we're talking about size of Char, what's the
difference between Char and char?

--- In [EMAIL PROTECTED], "Don Heitzmann"
<[EMAIL PROTECTED]> wrote:
> I think a (char *) is 4 bytes, not three... If
you're going to dynamically
> allocate the array of pointers, why not say "level *
sizeof(Char *)"
> instead of "3 * sizeof(Char)"?  In fact, the size of
a "Char" really has no
> relevance to this array.
> The fact that you're only allocating about 3/4 of
the memory you really need
> would explain why your program stops "roughly" 3/4
of the way through the
> array.
> -don
> "Brian Preston" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >
> > I'm getting the error that says 'your app just
wrote
> > to memory location 0x0BLAH...' - basically, I
didn't
> > allocate enough memory with my buffer.
> >
> > I'm simply trying to create a list of 1 to n,
where n
> > is a random number from 1 to 10.  I can't find any
> > pattern in when the error occurs; it will crash on
the
> > 6th iteration when I'm trying to create 8, or on
the
> > 3rd iteration when I'm trying to create 4, etc.
etc.
> > What am I doing wrong?
> >
> > Here's the code:
> >
> > static Char ** diffs (defined as static so it will
> > hang around long enough
> > for the list to use it, then freed upon FrmClose)
> > static void CreateDiffList() {
> >  int d=0;
> >
> >  level = GetRandom(10)+1;
> >  diffs = (Char **) MemPtrNew (level * 3 *
> > sizeof(Char));
> >
> >  for (d; d < level; d++) {
> >   diffs[d] = (Char *) MemPtrNew(3 * sizeof(Char));
> >   if ( d<9) {
> >    StrCopy(diffs[d], " ");
> >    StrIToA(SBuf2, d+1);
> >    StrCat(diffs[d], SBuf2);
> >   } else { StrCopy(diffs[d], "10");
> >   } StrCopy(SBuf2, diffs[d]);
> >  }
> >
> > 
LstSetListChoices(GetObjectPtr(StartDifficultyList),
> > diffs, level);
> > 
LstSetSelection(GetObjectPtr(StartDifficultyList),
> > level-1);
> >
> > }
> >
> > Thanks
> >


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to