Frage deutsch
~~~~~~~~~~~~~~
Was bedeutet '$DYNAMIC
 

Question English
~~~~~~~~~~~~~~~
What's the meaning of '$DYNAMIC?
 

Antwort 1
~~~~~~~~
[ von Thomas Antoni, 19.5.02 ]
.
'$DYNAMIC ist ein sogeannnter "Meta-Befehl", das heißt, eine Miteilung an der Interpreter/Compiler und kein direkt ausführbarer QB-Befehl.
 
Mit DYNAMIC kannst Du ein "dynamisches" Feld deklarieren, dessen Feldlänge sich zur Laufzeit noch verändern lässt. Ein solches Feld läßt sich auch ganz wieder aus dem Speicher entfernen.
 
*** Variante 1
DIM DYNAMIC feld%(15) 'Feld konstanter Länge deklarieren
ERASE feld% 'Feld aus dem Speicher entfernen
 
*** Variante 2
INPUT n%
DIM feld% (n%):... 'Feld variabler Länge deklarieren;Feldlän-
INPUT m% 'ge ändern und Feld initialisieren ==> alte
REDIM feld%(m%) 'Daten werden gelöscht {11/265}, evtl. vor-
'her in Hilfsfeld retten
ERASE feld% 'Feld aus dem Speicher entfernen
 
*** Metabefehle '$STATIC und '$DYNAMIC
Über diese am Anfang einer BAS-Quellsprachedatei anzugebenden 'Metabefehle' läßt sich voreinstellen, ob alle nachfolgenden per DIM deklarierten Felder statisch oder dynamisch angelegt werden sollen.
 
(Auszug aus meinem QBasic-Kochbuch, das Du auf
www.qbasic.de in der Tutorial-Rubrik herunterladen kannst)
 

Answer 2
~~~~~~~~~
[ aus der FAQ der
news: comp.lang.basic.misc , 14.6.2002 ]
.
What is the difference between STATIC and DYNAMIC memory?
.
ANSWER
.
For some unknown reason this seems to be a popular concept that eludes programmers. STATIC memory is memory allocated to the application at execution time. It is generally a section of data stored in the EXE that is loaded into memory. DYNAMIC memory is memory allocated by the executable during execution and the memory must be initialized by the program. Some systems also require that the program handle freeing the memory or they will not return it to the system until a re-boot.
 
Freeing the memory relieves its usage from your program and allows the system to use it for something else, either by another program or yours. Basic's variable length strings are dynamic, but freeing and allocating is done without your help. You can in many implementations, allocate arrays dynamically and then free them or resize them with ready.
Basically it allows you to manage memory a little better with your program.
 

[ The QBasic-MonsterFAQ --- Start Page: www.antonis.de/faq ]