could I be more stupid or blind??? off course that was the problem. Thanks a lot.
"Craig Austin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > I want to load two arrays with the information of a database, but I have > > problems related with memory (the emulator and a palm device crashes with > > this sentences). This is the code, any idea??? > > ... > > > > typedef struct { > > Int16 conProvincia; > > Char nomProvincia[15]; > > } TRecProvincia; > > > > ... > > err = openDatabase(name,&gDProvin,kCardNumber,kCreator,kType); > > MAXPROV=DmNumRecords(gDProvin); > > ... > > > > Int16 *lista_conprovincia; > > stringtype *lista_nomprovincia; > > TRecProvincia *p; > > > lista_conprovincia = (Int16*) MemPtrNew(MAXACT * sizeof(Int16)); > > lista_nomprovincia = (Char**) MemPtrNew(MAXACT * sizeof(Char*)); > > Shouldn't "MAXACT" be replaced with "MAXPROV"? Depending on your value of > MAXACT, you could be overflowing you buffer below. This could be the cause > of your crash. > > > > > for (i=0; i<MAXPROV;i++) > > { > > h = DmQueryRecord(gDProvin,i); > > p = (TRecProvincia *)MemHandleLock(h); > > lista_conprovincia[i] = (Int16) MemPtrNew(sizeof(Int16)); > > lista_nomprovincia[i] = (Char *) MemPtrNew(15); > > lista_conprovincia[i] = p->conProvincia; > > StrCopy(lista_nomprovincia[i], p->nomProvincia); > > MemPtrUnlock(p); > > } > > By the way, you are going to have a memory leak here. You don't need the > line: > > > lista_conprovincia[i] = (Int16) MemPtrNew(sizeof(Int16)); > > You are allocating memory, then assigning another value over the top of the > memory address. > > > Hope that helps, > > > Craig > > > -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
