How many free memory there is in runtime

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
fraespre
Member
Posts: 21
Joined: Mon Aug 19, 2019 8:08 pm

How many free memory there is in runtime

Post by fraespre »

Dear all,

Do you have any trick to know, in runtime, how many free memory (RAM) there is in the machine?

It could seems a rookie question. But I've been searching in the forum and I can't found any clear response.

Thanks in advanced and cheers,
User avatar
dom
Well known member
Posts: 1320
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Take a look at this thread: https://www.z88dk.org/forum/viewtopic.php?id=11000 - it's talking about the CP/M platform but the hints are equally valid for the ZX as well.
fraespre
Member
Posts: 21
Joined: Mon Aug 19, 2019 8:08 pm

Post by fraespre »

Thanks Dom. But I had already tried this command (mallinfo) and it doesn't work for me. I find a compilation error.

I finish testing this code:

Code: Select all

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

void menu_start() {
  unsigned int total,largest;
  
  tool_cleanScreen(INK_BLACK|PAPER_WHITE, 32);
  tool_printStr(6, 4, INK_BLACK|PAPER_WHITE, "Free Memory:");
  mallinfo(&total,&largest);
  tool_printNum(20, 4, 7, total, 7);
  sp1_UpdateNow();
  in_wait_key();
  ...
The compilation command line is:

Code: Select all

zcc +zx -v -m -startup=31 --opt-code-size -clib=sdcc_iy -SO3 @../src/main.lst -pragma-include:../src/zpragma.inc -o gamesp1 -create-app
The compilation error is:

Code: Select all

PROCESSING ../src/menu.c
zsdcpp -iquote"." -D__Z88DK -D__SPECTRUM -DSPECTRUM -D__SPECTRUM__ -D__Z80 -DZ80 -D__SDCC -D__SDCC_IY -isystem"C:\mio\soft\dev\z80\z88dk-win32-1.99C\lib\config\\..\..\\include\_DEVELOPMENT\sdcc"  -D__SDCC  "../src/menu.c" "C:\Users\javi\AppData\Local\Temp\zcc605813.i2"
zpragma  < "C:\Users\javi\AppData\Local\Temp\zcc605813.i2" > "C:\Users\javi\AppData\Local\Temp\zcc605813.i"
zsdcc --constseg rodata_compiler   --reserve-regs-iy -mz80 --no-optsdcc-in-asm --c1mode --emit-externs  --no-c-code-in-asm --opt-code-size  --no-peep --peep-file "C:\mio\soft\dev\z80\z88dk-win32-1.99C\lib\config\\..\..\/libsrc/_DEVELOPMENT/sdcc_peeph_cs.3"  < "C:\Users\javi\AppData\Local\Temp\zcc605813.i" -o "C:\Users\javi\AppData\Local\Temp\zcc605813.opt"
../src/menu.c:20: warning 112: function 'mallinfo' implicit declaration
../src/menu.c:20: error 101: too many parameters
../src/menu.c:28: warning 85: in function menu_start unreferenced local variable : 'largest'
Would it be possible that I left something?
fraespre
Member
Posts: 21
Joined: Mon Aug 19, 2019 8:08 pm

Post by fraespre »

Hi again,

I continued reading and I found that the new lib use other command.
Thus I changed my code with this:

Code: Select all

#include <stdlib.h>
#include <string.h>
#include <stropts.h>
#include <intrinsic.h>
#include <malloc.h>
...

void visit_heap_block(heap_info_t *hi) {
   if(hi->type==2) {
     tool_printStr(6, 4, INK_BLACK|PAPER_WHITE, "Free Memory:");
     tool_printNum(20, 4, 7, hi->size, 6);
   }
}

void menu_start() {
  unsigned int total,largest;
  
  zx_border(INK_YELLOW);
  tool_cleanScreen(INK_BLACK|PAPER_WHITE, 32);
  tool_printStr(8, 2, INK_BLACK|PAPER_WHITE, "==  M E N U  ==");
  heap_info(_malloc_heap, visit_heap_block);
  sp1_UpdateNow();
  in_wait_key();
  ...
And It works !!! Thanks.
Post Reply