Page 1 of 1
Default stack size / memory map for CP/M
Posted: Sun Sep 22, 2019 10:47 pm
Does the stack start at one side and the malloc from the other and they grow towards each other? Or is there is a fixed stack size? Is there stack overflow checking?
Posted: Mon Sep 23, 2019 9:18 am
If you're using newlib, then Alvin explained heap sizing in this post: https://www.z88dk.org/forum/viewtopic.p ... 713#p14713
For classic, AMALLOC is the easiest way to do things, it's detailed in this thread: https://www.z88dk.org/forum/viewtopic.php?id=5859
For CP/M, any heap will start from the end of BSS memory and extend up to the values configured above. If it's dynamically sized using the above mechanisms, the actual size will change depending on the TPA of the machine that it's running on.
There's no bounds checking, it would be possible to add on entry to a function, but even with a fudge factor we might still overlap depending on the complexity of the function.
Posted: Mon Sep 23, 2019 12:05 pm
I am using newlib (zcc +cpm -clib=sdcc_iy -create-app %1.c -o%1.com).
What I want to do is keep the dynamic area from running into a specific stack size. I'd rather it return NULL on malloc when it is out of memory.
I tried this as a test to see how large a block I can malloc, but changing the stack size does not diminish the block size.
#define CRT_STACK_SIZE 16384
unsigned int i1;
Posted: Mon Sep 23, 2019 2:11 pm
Try replacing the #define with following:
#pragma define CRT_STACK_SIZE = 16384
With that option I get a value of 44800 using zxcc, without it it's 60672
Posted: Mon Sep 23, 2019 2:13 pm
Excellent - yes - that does it! Thank you dom!