Page 1 of 1

Is there a coreleft() function in alloc.h?

Posted: Sat Sep 21, 2019 4:38 pm
by alank2
Is there a coreleft() function in alloc.h? or something similar? I'd like to see how much memory is available when loading a CP/M program.

Posted: Sat Sep 21, 2019 10:09 pm
by dom
There's mallinfo() which should give you the space remaining and the largest available chunk.

Posted: Sat Sep 21, 2019 10:48 pm
by alank2
Thanks, I am trying:

Code: Select all

#include <stdio.h>
#include <stdarg.h>
#include <alloc.h>

int main()
    unsigned int total,largest;


    printf("%u %u\n",total,largest);

    return 0;
main.c:9: warning 112: function 'mallinfo' implicit declaration
main.c:9: error 101: too many parameters

Posted: Sat Sep 21, 2019 11:47 pm
by dom
Ah. I didn't realise you were using newlib. It looks like you can use heap_info(_malloc_heap, <callback_function>) and walk the blocks to determine usage.

Given your other problem (fopen not working), it's probably worth switching to classic (drop the -clib= option) to get the features you want.

Originally, the classic library and new library were completely different code bases, however over time they have converged with the result that the only differences are as follows:

* Classic supports many more targets and has different way of implementing the crt0 startup file
* <stdio.h> is a different implementation that supports file io
* Classic supports multiple floating point libraries for pure sccz80 compilations
* Classic provides the cross platform libraries detailed below
* Classic tends to be tuned at link time, newlib at library build time