Palm OS fatal error on array processing (C coding)

Posted on 2007-07-31
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
    LVL 86

    Accepted Solution

    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

    Oh, and don't forget to

    delete [] sdata;

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

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    A brand new malware strain was recently discovered by security researchers at Palo Alto Networks dubbed “AceDeceiver.” This new strain of iOS malware can successfully infect non-jailbroken devices and jailbroken devices alike.
    The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now