[cc65] Config files and heap space

From: Dan Winslow <DWinslow1aiminstitute.org>
Date: 2009-05-20 16:10:13
The following function is intended to display a rough estimate of the amount of heap available at program startup :

void heap_avail(void)
{
    int x;
    char *t;
    x=10;
    while(1)
    {
      t=malloc(x);
      if ( !t ) break;
      free(t);
      x+=10;
    }
    if ( x > 10 ) 
      x-=10;
    else
      x=0;
    cprintf("heap avail: %i bytes\r\n",x);
}

( I know its crude at best, and if there are better ways of doing this I'd be glad to hear of them, but this is not what I am asking about )

If the the config file I am using has the start address set at 2E00 ( STARTADDRESS: default = $2E00; ), I get around 30k reported by the above function. If the config file I am using has the start address set at 2000 ( which should be ok with the DOS I am using ), I get 0 k reported. The program seems to run fine either way..altough I am not using malloc in my code (yet).

My question really deals with how heap is allocated and why a change to startaddress would have such a dramatic effect.

Thanks
Dan Winslow

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Wed May 20 16:10:29 2009

This archive was generated by hypermail 2.1.8 : 2009-05-20 16:10:31 CEST