Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Palm OS fatal error on array processing (C coding)

Posted on 2007-07-31
2
Medium Priority
?
280 Views
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:
sdata[2000]=5;
it still failed!!!
Please help...  thanks
0
Comment
Question by:jilsoft
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
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.
0
 
LVL 86

Expert Comment

by:jkr
ID: 19604303
Oh, and don't forget to

delete [] sdata;

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

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