I apologise to all of you for having put the entire code of mine 
here, but I am really becoming helpless.

I am trying to write a native palm application in which you have 
links similar to the ones used in Web Browser. Clicking on the link ( 
i.e. an "underlined" text on Palm ) takes you to another form/screen. 
I have used a "Queue" class [ please see below ] in which I keep on 
adding all the underlined text. This is collected in the form 
of "RectangleType" in the "Queue" class. 

The "Queue" class has been implemented using Linked List as a Data 
Structure. In the implementation of the add() method of this class, I 
need to add a new node. While allocating the memory to this node, I 
was using "new" keyword. However, it was giving me errors. So I chose 
to take the memory dynamically from the "Memory Manager" of the Palm 
OS. Even this has not helped. The application compiles smoothly but 
at run time when I click on a hyperlink on the Palm screen, the 
program crashes and takes me straight to some assembly level 
instructions for debugging. The selected function is always add() of 
class Queue in this state. I am not at all familiar with assembly 
language . 

Specifically, what I wanna know is when I create a new object 
dynamically, how do I about memory allocation : do I have use "new" 
keyword as in a traditional C++ program or do I have to make use of 
the methods from Palm OS Memory Manager ?

Please tell me what is going wrong in my code. 

Again I apologise for the inconveniency caused to all of you because 
of my lack of knowledge.

/*****************************************/

//////////  CLASS QUEUE ////////////////

class Queue {
  private:
    RectangleType rectangle;
    int isRed; // color of the underline : red if already visited 
else blue
    
    
    Queue *next; // pointer to the next node
    Queue *front, *rear;    
    
    // Is thid acceptable ? I am doing like this because I need to 
free the memory thru a different function    
    Queue* temp;
       
  public:
    Queue();  
    void add(RectangleType rect, int color);
    RectangleType remove();
    int size();
};

Queue::Queue() {
   rear = NULL;
   front = NULL;
   next = NULL;
   temp = NULL;
}

void Queue::add(RectangleType rect, int color) {
   //Queue *temp; // This is made as a member variable now
   
   //temp = new Queue;
   // Here try to the heap from the Memory Manager in lieu of 
invoking the new

   //unsigned long length = sizeof(rectangle) + sizeof(int);
   unsigned long length = sizeof (Queue);
   temp = (Queue*)MemHandleLock(MemHandleNew( length ));
   
   
   
   if( temp == NULL ) { return ; }
   
   // initialise the data of this node
   temp->next = NULL;
   temp->rectangle = rect;
   temp->isRed = color;
   
   if( front == NULL ) { // null list
      front = temp;     
   }
   else {
      rear->next = temp;
   }
   rear = temp;
   
   Err r = MemHandleUnlock ((Queue**)temp) ;

   
  // FrmCustomAlert( AltDebugAlert, " ok ok ok", NULL, NULL );
   
   return ;
}

RectangleType Queue::remove() {

   // Queue *temp;
   Err error;
    RectangleType rect;
    
    temp = front;
    rect = temp->rectangle;
    
    if( front == rear ) { // ONE NODE ONLY
       front = rear = NULL;
    }
    else {
       front = temp->next;
    }
    
   // delete temp;     
   error = MemHandleFree((void**)temp) ;
    
    return rect;
    
}

int Queue::size() {
    int i = 0;
    
    while( front != NULL ) {
       i++;
       front = front->next;
    }
    
    return i;
}

/************************************************/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to