Dirty Blocks vs. Clean Blocks

When you load a block of virtual memory with _vload, you must specify either the flag _VM_CLEAN or _VM_DIRTY, indicating that the block is either “clean” or “dirty.” If your program reads the block of memory but does not modify its contents, the block is clean. If your program modifies the block of memory, the block is dirty. This flag tells the virtual memory manager what to do when it needs the region of DOS memory that the loaded block occupies. If a block is clean, the virtual memory manager is free to overwrite it the next time it has to load a new block of memory. If a loaded block is dirty, the virtual memory manager must write out its contents to auxiliary storage before it loads a new block.

Every block of virtual memory that you allocate must be flagged as dirty at least once, if only to initialize its contents. If the block is treated as read-only from that point forward, it can be flagged as clean during subsequent loads. Otherwise, it must be flagged as dirty each time the program modifies it.

Note that when a dirty block is saved, its contents are retained only until the block is freed or the virtual memory manager is terminated. If you want to save the block's contents beyond that point, you must load the block into DOS memory and explicitly copy its contents to a permanent disk file.