🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.transputer
1 messages
1 total messages Started by Richard Ohran Thu, 18 Jan 1990 00:30
Re: Dynamically determining memory size
#473
Author: Richard Ohran
Date: Thu, 18 Jan 1990 00:30
44 lines
1748 bytes
Here is a procedure written in Modula-2 which finds all the memory
between the top of the process and the top of memory.
It returns the starting address in the variable "adr" and the
number of available bytes in "size". It checks for both
memory wraparound and non-existent memory address regions.
 
 
PROCEDURE Allocate(VAR adr: POINTER TO BITSET; VAR size: CARDINAL);
 
  VAR x: POINTER TO ProcessState; 
      z,zchanged:BITSET;
      b:POINTER TO BITSET;
BEGIN (*size is in bytes*)
  InitProcessPtr(x);
  adr:=x^.ProcessTop;    (* adr now has the first memory address above
                           the running program*)
  size:=0;
  LOOP
    INC(adr,200H);
    b:=CARDINAL(adr) MOD 10000H + 80000000H; (*creating wraparound address*)
    IF adr^=b^ THEN (*potential memory wraparound*)
      z:=adr^;
      zchanged:=z/{0..31}; (*exclusive or*)
      adr^:=zchanged;
      IF adr^=b^ THEN (*wraparound*)
        adr^:=z;
        EXIT
      END
    END;
    (*now check for non-existent memory*)
    z:=adr^;
    z:=z/{0..31}; (* exclusive or*)
    adr^:=z;
    IF adr^<>z THEN EXIT END;
    adr^:= z/{0..31};(*restore data for valid word*)
    INC(size,200H);
  END;
  adr:=x^.ProcessTop;
END Allocate;
 
Hope this helps. If you have any questions about how it
works, call me at 801-226-8978.
 
Richard Ohran
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads