Learn how to a build a cloud-first strategyRegister Now


Palm OS fatal error on array processing (C coding)

Posted on 2007-07-31
Medium Priority
Last Modified: 2013-12-27
Situation: I am using the Garnet OS Development Suite. I am writing some C code for a palm Tungsten E2.
I am having problems with a fatal error when using an array.  To narrow down the problem, I used the following code:   for (i=0 ; i<5000,i++) sdata[i] = 5;
declaration:  unsigned char sdata[5000];
No coding (other than data declaration) preceded the code, when I installed the program on the palm and accessed it failed during the for loop. By playing with the upper limit on i, I determined that it failed with an upper limit of approx 1800.  I then replaced the for loop with the code:
it still failed!!!
Please help...  thanks
Question by:jilsoft
  • 2
LVL 86

Accepted Solution

jkr earned 2000 total points
ID: 19604299
You seem to be declaring the array locally on the stack, which is prone to overflow - try

unsigned char* sdata = new unsigned char[5000];

for (i=0 ; i<5000;i++) sdata[i] = 5;

and that should work fine, since the memory is allocated on the heap that way.
LVL 86

Expert Comment

ID: 19604303
Oh, and don't forget to

delete [] sdata;

when you no longer need it, or you'd cause memory leaks.

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question