Mechanically / syntactically you are using the correct functions for memory
management. (So in a pure PalmOS sense, we are done.)
However, your code below has so many unknowns that I couldn't just look at it and tell
you an error.
If you can pinpoint the crash to a specific line of code, it would help.
Otherwise, it's basic memory management - have you written to memory outsied of what's
allocated?
Is the data you're accessing write protected and would need DmWrite?
One thing that seems like a bug off the top of my head is that you are allocating
enough space for ONE CRawHist in rawhistData, but
you later refer to rawhistData[i] as if you had allocated an array. So if i != 0 that
will crash.
In general, check all the values of your input variables and make sure you're
accessing the memory you think you are. Also view the
actual memory and arrays in the debugger to help.
Good luck!
- Jeff
"Nesselhauf, John" wrote:
> Hi,
>
> I am having a problem with memory, I think. I keep getting a fatal error
> when I run
> this code:
>
> CRawHist *rawhistData = MemPtrNew(sizeof(CRawHist));
> datain2* phistrec;
>
> CharPtr chrtnbuf1;
> int ndatasize;
> char strint_buf[400];
> int nmemcount;
>
> ndatasize = 288;
> phistrec->count1 = 18;
> nmemcount = 16;
>
> chrtnbuf1 = ReceiveSerial( ndatasize/2, 60 );
>
> // Move information into a variable.
> MemSet(&strint_buf, sizeof(strint_buf), 0x00);
> MemMove(&strint_buf, chrtnbuf1, ndatasize/2);
>
> // populate an array with the same information.
> for( i=0; i<=(phistrec->count1/2)-1; i++ )
> {
> MemSet(&rawhistData[i].vtm1, 16, 0x00 );
>
> MemMove(&rawhistData[i].vtm1, &strint_buf[i*nmemcount], 16);
>
> if( rawhistData[i].vtm1 <= 10 )
> {
> break;
> }
> nrecord_no++;
> }
>
> MemPtrFree( rawhistData );
>
> Am I doing this correctly? This code seemed to work fine for a while. I
> fixed something totally
> unrelated then recompiled and now it fails in this code.
>
> Thank you for your help.
>
> John
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe, please see
>http://www.palmos.com/dev/tech/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/