TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Erik Huelsmann
from: Jonathan de Boyne Pollard
date: 1994-07-22 19:30:00
subject: Allocated memory - how d

EH>
  > begin
  >  writeln( memavail); { write the number of remaining free bytes }
  >  getmem( p, 4);      { allocate 4 bytes }
  >  writeln( memavail); { write the number of remaining free bytes after alloc
  >  freemem( p, 4);     { release the 4 bytes again }
  >  writeln( memavail); { again remaining }
  > end.
  >
  > this program outputs:
  >
  > 774430
  > 774500
  > 774430
EH>

  Always remember that most languages allocate memory in one big block
  from the operating system, and them suballocate smaller amounts from
  that block as and when the application asks for them.

  Borland C++ for OS/2 is a good example.  Internally it allocates
  memory from OS/2 in 4Mb chunks, and then malloc() parcels it out in
  smaller chunks.

  This has two effects.  Firstly, the first call to allocate memory will
  request this large chunk from the operating system, and OS/2 will see
  no more allocation requests until that has all been used.  And
  secondly, as far as OS/2 is concerned, the application is allocating
  memory in 4Mb chunks, and so will report it that way.

  Your memavail function in PASCAL is probably going straight to OS/2 to
  obtain the size of the largest free memory block (not a good
  indication of how much memory is actually free, BTW), whereas getmem()
  is doing some internal voodoo much like I have described so that it
  doesn't have to call OS/2 on each memory allocation.

  Note that the amount of memory left to an application on a
  multitasking system with virtual memory is not a very useful figure,
  as the user is perfectly entitled to suddenly crank up Lotus Notes in
  the background, and bang go several megabytes of memory that only
  seconds ago were reported to your program as being available for use.

  > JdeBP <
___
 X MegaMail 2.10 #0:

--- Maximus/2 2.01wb

* Origin: DoNoR/2,Woking UK (0483-725167) (2:440/4)
SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 413 430
SEEN-BY: 711/807 808 809 934 942 712/353 623 713/888 800/1
@PATH: 440/4 141/209 865 820 3615/50 229/2 12/2442 711/409 54/54 711/808 809
@PATH: 711/934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.