Stacksize in KOS

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

Stacksize in KOS

Post by RyoDC »

Are KOS limiting stacksize that can be used by my application to some explicit value?
Or it's just increased each time I enters a new function?
I'm talking about stack for automatic (function scope) variables.

How many memory we have for static variables?
How do I try to build a Dreamcast toolchain:
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5666
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Stacksize in KOS

Post by BlueCrab »

Each created thread has a stack size of THD_STACK_SIZE (which is defined in kernel/arch/dreamcast/include/arch/arch.h), and defaults to 32768 bytes in relatively recent versions (anything from the Git repository, and for a while back from the SVN as well) of KOS, and is allocated from the heap at thread creation time.

The main kernel thread does not have any explicit limit on the stack size, and will simply grow down until it hits the heap (at which point, when you try to allocate memory from the heap, you will get a failed assertion). So, unless you're using threads, there is no explicit limit on the amount of stack space you have.

If you have some reason to change the default of 32768 per normal thread, you can change the #define in that file. One word of warning: do not make it less than 16384 or so if you plan to do anything with files. The realpath function uses more than 8k of stack space, and it gets called by pretty much every single open/fopen/fs_open call.
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

Re: Stacksize in KOS

Post by RyoDC »

So the thread model are now in the core of KOS?
Like all work with hardware now inlcudes threads, no poll mode anymore?
How do I try to build a Dreamcast toolchain:
Image
Post Reply