Thanks for responding!

At 06:04 AM 12/2/2001 -0800, you wrote:
>It doesn't have enough information.  

Sorry, I was trying to keep the posted stuff small.  Here goes...

It might help if I gave you a little context.  What I'm writing, 
here, is a D&D3 character sheet.  I've been programming for about 
30 years but this is my first _real_ Palm program.  I know I'm 
being sloppy in some places (i.e, not having allocated the whole 
thing on the heap -- I plan to store it in a database and use it 
from there; and by not packing my strings).

>It would be better if you can show how you declare the struct, 

This is pretty big so the short version follows first.  'PC' is a 
structure containing other structures.  At one point in my code
development, I changed the size of one of PC's component arrays
and got the aforementioned crash.  I changed the code back and 
printed out the sizeof(PC) with:

        StrPrintF (p, "size is %d", sizeof(PC));
        WinDrawChars (p, StrLen(p), 1, 16);

Trial and error showed me that I got the crash when the array
was big enough to push the whole size just over 4096 bytes.

The long version is:

#define CHARS_ON_LINE   40
#define MAX_LEVEL               20
#define CLASS_CNT               11
#define MAX_WEAPON              20
#define MAX_ARMOUR              10
#define MAX_EQUIP               40      // this is the thing I varied

typedef struct PC {
        void            (*clean)(struct PC *me);
        Char            name[CHARS_ON_LINE];
        Boolean prof[proficiencyCount];
        Alignment       align;
        int             ability[ATTR_COUNT];
        ClassLevel      classLevel[CLASS_CNT];
        int             weaponCount;
        int             wpnInHand[2];
        Weapon          weapon[MAX_WEAPON];
        int             armourCount;
        int             armour1;
        Armour          armour[MAX_ARMOUR];
        int             equipCount;
        Equipment       equip[MAX_EQUIP];
        PCdisplay       display;
} PC;

The data types Alignment, ClassLevel, etc. are given at the end of
this letter.

>and how it "gets bigger than 4096B", 

When MAX_EQUIP is set at 40, the sizeof(PC) is something like 4056
bytes.  When it's 41 (or 100 or 50), the size is something like
4109 bytes.

>the codes that working on the struct.

This gets pretty big so I'll summarize.  I'm reading data from
a memo pad database memo and stuffing parsed values into a 'PC'
structure.  I've verified that I'm reading the memo I think I'm 
reading and that I'm parsing it pretty-much correctly by printing 
things from the PC structure.  I parse an integer, for example,
with the following code:

        static int getInt (char **p)
        {
                int     ansr    = 32767;
                if ((p==0) || (*p==0)) // print error and return
                skipSpace(p);
                ansr = StrATol(*p);
                while (isNum(**p)) ++*p;
                return ansr;
        }

Where:

        static void skipSpace (Char **p)
        {       // error checking elided
                do {
                        while (isWhite(**p) || ((**p)==','))
                                ++*p;

                        if ((**p) == COMMENT_CHAR) {
                                while(!isEOL(**p)) ++*p;
                        }
                } while (isWhite(**p) || ((**p)==','));
        }

And:

        #define isNum(c) (((c)>='0') && ((c)<='9'))
        #define isWhite(c) (((c)==' ') || ((c)=='\t') || ((c)=='\n'))
        #define isEOL(c) ((c)=='\n')
        #define COMMENT_CHAR '#'

There are similar routines for reading enums and higher-level
structures.

This is all called from 'initMe' which does, roughly, the following:

        LocalID dbId    = 0;
        DmOpenRef       dbRef   = 0;
        Char            *fromP  = 0;
        Handle          record;
        CharPtr rP;

        dbId = DmFindDatabase (0, "MemoDB");
        if (dbId != 0)
                dbRef = DmOpenDatabase (0, dbId, dmModeReadOnly);
        //...

        record = DmGetRecord (dbRef, indexIGotInTheCode);
        fromP = rP = MemHandleLock (record);
        //...
        foo = getInt (&fromP);
        //...

        MemHandleUnlock (record);
        DmReleaseRecord (dbRef, indexIGotInTheCode, 0);

>When you suspect that only the size cause the problem, it might 
>not be true...

That's a good point that I hadn't really considered.  I had presumed
that changing the size of an array in PC would not affect something
like, for example, parsing off the end of the original database 
record.  I was further pushed to believe that there was some sort
of wall at 4K because the size of 'PC' for working vs. non-working 
versions of the code were *SO* close to that power of 2 (one, in 
fact, that is a limit for other things -- most notably stack size).

I also hope that it's not some bug in my code because I really 
don't want to bother this board for non-palm programming issues.

Here's some of the other structures that make-up PC.  I'm not sure
they're relevant but I included them for backup information.

typedef struct {
        Char    fortSave[MAX_LEVEL];
        Char    refSave[MAX_LEVEL];
        Char    willSave[MAX_LEVEL];
        Char    attackBonus[MAX_LEVEL][5];
} CharClass;

typedef enum { /*...*/ } Where;
typedef struct {
        Char    name[CHARS_ON_LINE];
        int     lbs;
        int     tenthLbs;
        int     num;
        Where   where;
} Equipment;

typedef struct {
        Equipment       equip;
        int             aBonus;
        int             maxDexBonus;
        Boolean isShield;
        int             aCheckPenalty;
        int             spellFailure;
        int             speed30;
        int             speed20;
} Armour;

typedef enum { /*...*/ } WeaponType;
typedef enum { /*...*/ } AmmoUse;
typedef enum { /*...*/ } AmmoType;
typedef enum { /*...*/ } Handedness;

typedef struct {
        int     num, d, plus;
} Dice;

typedef struct {
        int     minThread, damInt, damFract;
} Critical;

typedef struct {
        Equipment       equip;
        WeaponType      weaponType;
        AmmoUse ammoUse;
        AmmoType        ammoType;
        Handedness      handedness;
        Boolean isRanged;
        Boolean isHand;
        Dice            damage;
        Critical        critical;
        int             ftRange;
} Weapon;

typedef struct {
        int             level;
        CharClass       *charClass;
} ClassLevel;

typedef enum {/*...*/} Alignment;

/*...*/






--
Wade Guthrie                         |  
[EMAIL PROTECTED]                    | 
http://members.home.net/guthrie1/    | 
                                     | 
           

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

Reply via email to