TURBO PASCAL

Новости

Программы   

Turbo Pascal 

Игры

Документация   

Странности

FAQ

Ссылки

Форум

Гостевая книга

Рассылка

Благодарности

Об авторе

 68: How much memory will my TP program require?

 A: Get MAPMEM.EXE 
from ftp://garbo.uwasa.fi/pc/memutil/tsrcom35.zip
and put the following code within your Turbo Pascal program:
  Program faq;
  uses Dos;
  :
  SwapVectors;
  Exec (GetEnv('comspec'), '/c mapmem');
  Swapvectors;
Then you'll see a MAPMEM output something like this
  Psp  Cnt   Size Name       Command Line        Hooked Vectors
  ---- --- ------ ---------- ------------------- --------------
        2  26,896 DOS
  0694  2   3,392 COMMAND                        2E
        1      64 ---free---
  0776  2   1,488 MARK       scrollit
  07D6  2  70,816 FAQ                            FF
  1923  3   2,752 command                        22 23 24
  19D2  2 549,712 ---free---
          655,344 ---total--
The memory requirement of your program FAQ.PAS is 70,816. Do 
not
confuse this figure with the physica size of your program. The
memory requirement affected among other things by the Memory
Allocation Sizes Directive. For example you might have
{$M 16384,0,50000}
-Date: Sun, 12 Jun 1994 
10:22:18
-From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
-Newsgroups: comp.lang.pascal
-Subject: Re: How much memory will my TP program require?
   I think this is a hard 
question, and probably needs a longer
answer than you gave.  Yours isn't quite right, because TP will
allocate memory that it doesn't need if you set the heapmax
parameter too high.  Your program will run in less memory than
MAPMEM reports. Here's a quick attempt at it:
   TP DOS programs use memory in 4 or 5 blocks:  fixed code, 
static
data, the stack, sometimes overlaid code, and the heap.  TP 
Windows
programs add a local heap to this list, but don't use overlays.  The
discussion below deals with real mode DOS programs.
   The size of the code is determined by which procedures and
functions you use in your program.  In DOS, if you don't use
overlays, this is all fixed code, and the size is reported as 
"Code
size" in the Compile| Information listing in the IDE.  The ways 
to
reduce it are to use fewer procedures or make them smaller, or 
move
them to overlays.
   Static data consists of all the global variables and typed
constants in every unit.  It is reported as "Data size" in 
the
Compile|Information listing.  You can reduce it by declaring fewer
or smaller variables.
   If you use the $O directive to move code to overlays, then those
units won't count as part of your fixed code needs.  You will need
an overlay buffer at run-time; by default, it's the size of the
largest unit you use, but normally you'll change the size with
OvrSetBuf.  It's difficult to work out the best size of this block
except by trial and error:  if your program spends too much time
swapping, then make it larger; if you run out of memory, make it
smaller.  You'll need to use the .MAP file (see the Options| Linker
dialog to create one) to find the size of each unit.  Remember to
subtract the size of overlaid units from the reported "Code 
size"
when working out the size of fixed code.
  The stack is used for local variables in procedures.  Its size is
controlled by the first parameter to the $M directive; the default
size is 16K.  It's hard to predict exactly how much stack space your
program will use.  One way is to keep reducing the value until your
program aborts with a stack overflow, then use a slightly larger
value.  Another way is to fill the stack with a fixed value at the
start of your program, and at the end, see how many values were
changed.  Again, it's a good idea to allow for a margin of safety,
because hardware interrupts will use this space, and their size is
hard to predict.
   The heap is where New and Getmem get their allocated 
memory.  The
size is controlled by the 2nd and 3rd parameters to the $M
directive.  The heapmin value will always be allocated; if extra
memory is available, your program will ask for as much as 
possible,
up to heapmax.  If not enough memory is available to load all your
fixed code, data, stack and heapmin, DOS will refuse to load your
program.  You have nearly complete control over the size of the 
heap
that you need, determined by how much you use New and 
Getmem. The
only exception is that some of the standard units use heap space;
GRAPH and all the TurboVision units are examples.  To find how 
much
your program actually uses, you can reduce Heapmax until it fails,
fill the heap with a special value and look for changes, or monitor
the value of HeapPtr as your program progresses.
 

 Contents

На первую страницу

Rambler's Top100 Rambler's Top100
PROext: Top 1000

(с)Все права защищены

По всем интересующим вопросам прошу писать на электронный адрес

Hosted by uCoz