Path: chuka.playstation.co.uk!scea!greg_labrec@interactive.sony.com From: "Wayne K. Werner" Newsgroups: scea.yaroze.programming.codewarrior Subject: Re: Initializing the heap Date: 31 Oct 1997 09:26:19 GMT Organization: WermX Software Lines: 71 Message-ID: <01bce5de$a390af80$6fbf43ce@wkwerner> References: <01bce566$fdb8c1a0$a5bf43ce@wkwerner> <34596659.40D5@charlie.cns.iit.edu> NNTP-Posting-Host: port11.con2.com X-Newsreader: Microsoft Internet News 4.70.1161 Ed Federmeyer wrote: > Actually we GNU users "need" to do it too. I say "need" in > quotes, because it seems you can usually seem to get away with > doing a few small mallocs, without initializing the heap, Hmmm. I didn't know it was something that needed doing with the GNU compiler. I don't seem to recall seeing it, but many of the demos don't use dynamic vars anyhow. > One problem with putting it in the startup code is "how does it know > how much heap space to manage". Every project has different > dynamic memory needs, from "none" to 1Mb or more! (ie, tiny code, > huge data!) CW allows the size of the heap to be set in the target configuration. If you look at the method recommended in the new _psstart.c to init the heap, you will see that the size is calculated from linker defined variables: unsigned long lclHeapStart = (_end & 0xFFFFFFF0L)+0x10; // heap extends to the bottom of the stack. unsigned long lclHeapSize = ((_stack_addr-(_stack_size<<10)) & 0xFFFFFFF0L)-lclHeapStart; InitHeap((unsigned long *)lclHeapStart, lclHeapSize); It appears that they suggest to make the heap everything from the end of program to bottom of stack, not even taking heap size settings into consideration. Depending on whether data is placed before or after the program, this could cause problems. At any rate, I will come up with my own formula later to take into consideration the size set in the config and passed to the program by the linker. (I need to check out the name of the var that contains heap size, and am just to tired now!) At any rate, using linker defined vars will add an incompatability between GNU source and CW source. I always assumed that GNU users set heap size in a switch and that was that. It's tiresome making wrong assumptions all day! > I wound up just putting it in at the begining of my main, and it's only > one line of code. We already "need" to manually keep track of where > TIM, > TMD, VAG, etc data is loaded in memory, so it's only one more detail. Yeah, but I still find it problematic to init heap in the source. Heap is a feature of the language itself. I think maybe GNU should be "upgraded" to handle this issue correctly, and CW shouldn't be "downgraded" to be compatible. Then compiler specific issues of heap inititialization would be no issues at all. -- Wayne K. Werner wkwerner@con2.com