Default stack size / memory map for CP/M
Default stack size / memory map for CP/M
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?
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.
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.
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.
#include <stdio.h>
#include <alloc.h>
#define CRT_STACK_SIZE 16384
int main()
{
unsigned int i1;
char *p;
for (i1=65280;i1!=0;i1-=256)
{
printf("%u\n",i1);
p=malloc(i1);
if (p!=NULL)
{
printf ("%04x",p);
break;
}
}
return 0;
}
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.
#include <stdio.h>
#include <alloc.h>
#define CRT_STACK_SIZE 16384
int main()
{
unsigned int i1;
char *p;
for (i1=65280;i1!=0;i1-=256)
{
printf("%u\n",i1);
p=malloc(i1);
if (p!=NULL)
{
printf ("%04x",p);
break;
}
}
return 0;
}