piotrek
piotrek

Reputation: 1363

What does 'dirty-flag' / 'dirty-values' mean?

I see some variables named 'dirty' in some source code at work and some other code. What does it mean? What is a dirty flag?

Upvotes: 28

Views: 34561

Answers (4)

Adrian NH
Adrian NH

Reputation: 197

There's a deeper issue here - rather than "What does 'dirty mean?" in the context of code, I think we should really be asking - is 'dirty' an appropriate term for what is generally intended.

'Dirty' is potentially confusing and misleading. It will suggest to many new programmers corrupt or erroneous form data. The work 'dirty' implies that something is wrong and that the data needs to be purged or removed. Something dirty is, after all undesirable, unclean and unpleasant.

If we mean 'the form has been touched' or 'the form has been amended but the changes haven't yet been written to the server', then why not 'touched' or 'writePending' rather than 'dirty'?

That I think, is a question the programming community needs to address.

Upvotes: 18

Xiao Jia
Xiao Jia

Reputation: 4259

"Dirty" is often used in the context of caching, from application-level caching to architectural caching.

In general, there're two kinds of caching mechanisms: (1) write through; and (2) write back. We use WT and WB for short.

WT means that the write is done synchronously both to the cache and to the backing store. (By saying the cache and the backing store, for example, they can stand for the main memory and the disk, respectively, in the context of databases).

In contrast, for WB, initially, writing is done only to the cache. The write to the backing store is postponed until the cache blocks containing the data are about to be modified/replaced by new content.

The data is the dirty values. When implementing a WB cache, you can set dirty bits to indicate whether a cache block contains dirty value or not.

Upvotes: 5

Dietmar Kühl
Dietmar Kühl

Reputation: 153810

Generally, dirty flags are used to indicate that some data has changed and needs to eventually be written to some external destination. It isn't written immediate because adjacent data may also get changed and writing bulk of data is generally more efficient than writing individual values.

Upvotes: 43

sampson-chen
sampson-chen

Reputation: 47267

Dirty could mean a number of things, you need to provide more context. But in a very general sense a "dirty flag" is used to indicate whether something has been touched / modified.

For instance, see usage of "dirty bit" in the context of memory management in the wiki for Page Table

Upvotes: 8

Related Questions