Информационный сервер для программистов: Исходники со всего света. Паскальные исходники со всего света
  Powered by Поисковый сервер Яndex: Найдется ВСЁ!
На Главную Исходники Форум Информер Страны мира
   Управление Памятью    >>    clearmem
   
 
 Clear Memory to a Fixed Value at the Program Start  D.J. Murdoch 06.06.1991

Модуль для автоматической инициализации "кучи", стэка или сегмента данных заданным значением, например нулем.
CLEARMEM - A Turbo Pascal unit to automatically initialize the heap, stack, or data segment to a fixed value.



1k 
 

CLEARMEM - A Turbo Pascal unit to automatically initialize the heap, stack, or data segment to a fixed value. Written by D.J. Murdoch for the public domain. Interface: const filler : byte = 0; This byte is used as the initial value. A good choice for turning up uninitialized variables is $FF - this will often cause a range check, and will cause runtime error 207 if you try to use an uninitialized single, double or extended. procedure clear_heap; This procedure fills the heap with filler bytes. Automatically called in the initialization section. procedure clear_globals; This procedure fills all global variables (except those in the system unit) with filler bytes. Very dangerous! *Not* called in the initialization section (unless you change it). Written for TP 6.0; the source code gives hints on how to change it for other versions. procedure clear_stack; This procedure fills the unused part of the stack with filler bytes. SAFETY It's safe to call clear_heap any time; it'll fill all free blocks of 6 bytes or more on the heap with the filler byte. It won't necessarily do a perfect fill if the heap is fragmented, because the free list will overwrite the filler. It's also safe to call clear_stack any time, but is a bit less effective. Any interrupts that happen after your call will mess up the stack that you've just cleared, so local variables won't necessarily be properly initialized. It doesn't touch anything already allocated. It's definitely *NOT* safe to call clear_globals any time except at the very beginning of your program, and only then from the initialization section of this unit, and only if this is the very first unit that you Use in the main program.