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

Post Reply
alank2
Member
Posts: 44
Joined: Wed Mar 01, 2017 7:24 pm

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

Post 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.
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

There's mallinfo() which should give you the space remaining and the largest available chunk.
alank2
Member
Posts: 44
Joined: Wed Mar 01, 2017 7:24 pm

Post by alank2 »

Thanks, I am trying:

Code: Select all

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

int main()
  {
    unsigned int total,largest;

    mallinfo(&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
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post 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
Post Reply