pure C default stack and heap size

C and PASCAL (or any other high-level languages) in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
saulot
Captain Atari
Captain Atari
Posts: 189
Joined: Sat Sep 18, 2004 9:09 pm
Location: Warszawa
Contact:

pure C default stack and heap size

Postby saulot » Tue Apr 07, 2009 8:25 pm

Hello!
Anyone knows something about stack and heap size in PureC? What are the standard values and what are the safest settings?
How can I determine if the settings are too low or not optimal?
I've read on the net that these settings are system dependant, so how it relates to atari st/falcon TOS ?

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: pure C default stack and heap size

Postby Nyh » Tue Apr 07, 2009 11:00 pm

saulot wrote:Anyone knows something about stack and heap size in PureC? What are the standard values and what are the safest settings?
How can I determine if the settings are too low or not optimal?
I've read on the net that these settings are system dependant, so how it relates to atari st/falcon TOS ?

The default stack size is 4 kB.
If the stack size is to low the program might crash.
The heap size is all free memory that isn't used by the stack and the program. The OS will tell you the size of the heap with Malloc(-1). The heap size can not be set (you can enter a value in the linker but it is ignored).

If you do deep recursive function calls with lots of data in the stack you have to calculate the needed stack size and enter the calculated value with a nice safety margin.

If you want to know the stack usage write a small assembly routine that performs this function:
max_stack=max(start_stack-SP,max_stack);
And call this function at the start of you recursive functions and print the value of max_stack when the program has finished running.

I usually use a 16kB stack.

Hans Wessels

User avatar
saulot
Captain Atari
Captain Atari
Posts: 189
Joined: Sat Sep 18, 2004 9:09 pm
Location: Warszawa
Contact:

Re: pure C default stack and heap size

Postby saulot » Wed Apr 08, 2009 6:50 pm

Nyh: thanks for the tips. So there this linker heap option is totally useless, it seems that the manual missed to mention this 'feature' completely ;).
Is there something more (like list of known bugs somewhere)? I'm also curious about the last compiler version that was released (version 1.1 was the last one?)

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: pure C default stack and heap size

Postby Nyh » Thu Apr 09, 2009 12:46 pm

saulot wrote:Is there something more (like list of known bugs somewhere)? I'm also curious about the last compiler version that was released (version 1.1 was the last one?)

AFAIK Pure C 1.1 is the most recent version.
Pure C is very good but Pure C is not completely bug free. I once stumbled on a compiler error within a macro expansion of a function. I never took the time to find out what exactly goes wrong and why. That is the only real compiler bug I came across in all the time I have been using Pure C. That is almost 20 years if you count Turbo C too.

Hans Wessels

brianmanee
Atarian
Atarian
Posts: 1
Joined: Tue Apr 26, 2016 6:57 am

Re: pure C default stack and heap size

Postby brianmanee » Tue Apr 26, 2016 6:59 am

Variables allocated on the stack are stored directly to the memory and access to this memory is very fast, and it's allocation is dealt with when the program is compiled. When a function or a method calls another function which in turns calls another function etc., the execution of all those functions remains suspended until the very last function returns its value. The stack is always reserved in a LIFO order, the most recently reserved block is always the next block to be freed. This makes it really simple to keep track of the stack, freeing a block from the stack is nothing more than adjusting one pointer. More about.....Stack and Heap

Brian

User avatar
metalages
Atari freak
Atari freak
Posts: 50
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: pure C default stack and heap size

Postby metalages » Tue Apr 26, 2016 5:02 pm

Pure C is very good but Pure C is not completely bug free. I once stumbled on a compiler error within a macro expansion of a function. I never took the time to find out what exactly goes wrong and why. That is the only real compiler bug I came across in all the time I have been using Pure C. That is almost 20 years if you count Turbo C too.


I have noticed a strange stuff using Pure C for Rebirth (https://github.com/gibs75/demOS):
when you use pointer arithmetics and using short* or long* instead of char*, the compiler sometimes generates calls to ldivs instead of asr which is very sub-optimal. I noticed that because the linker does not find ldivs when compiling without any standard libs :)


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 1 guest