Local nonsatiation: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Dawynn
 
en>Nick Number
m repaired link(s) to disambiguation pages (you can help) - Bundle
 
Line 1: Line 1:
In [[computer science]], a '''tagged pointer''' is a common example of a [[tagged union]], where the primary type of data to be stored in the union is a [[Pointer (computer programming)|pointer]].  Often, the ''tag'' in a tagged pointer will be "folded" into the data representing the pointer, taking advantage of one of the following properties of pointers:
Hi there, I am Alyson Pomerleau and I think it sounds fairly good when you say it. Credit authorising is how he makes money. To perform lacross is something I really appreciate doing. Mississippi is where her house is but her husband wants them to move.<br><br>my site ... free tarot readings; [http://www.january-yjm.com/xe/index.php?mid=video&document_srl=158289 www.january-yjm.com],
* Pointers to certain types of data will often be ''[[Data Structure Alignment|aligned]]'' to the size of the data (4 bytes, 8 bytes, etc.), which leaves a few bits of the pointer unused. As long as code that uses the pointer properly [[Bit mask|masks out]] these bits, the pointer can be tagged with extra information.
* The [[virtual memory]] system in most modern [[operating system]]s reserves a block of logical memory around address 0 as unusable.  This means that, for example, a pointer to 0 is never a valid pointer and can be used as a special [[null pointer]] value.
 
== Null versus Aligned Pointer ==
 
Use of 0 to represent a null pointer is extremely common, with many programming languages (such as [[Ada programming language|Ada]]) explicitly relying on this behavior.  In theory, other values in an operating system-reserved block of logical memory could be used to tag conditions other than a null pointer, but these uses appear to be rare, perhaps because they are at best [[Porting|non-portable]]. It is generally accepted practice in software design that if a special pointer value distinct from null (such as a [[Sentinel value|sentinel]] in certain [[data structure]]s) is needed, the programmer should explicitly provide for it.
 
Taking advantage of the alignment of pointers provides more flexibility than null pointers/sentinels because it allows pointers to be tagged with information about the type of data pointed to, conditions under which it may be accessed, or other similar information about the pointer's use.  This information can be provided along with every valid pointer.  In contrast, null pointers/sentinels provide only a finite number of tagged values distinct from valid pointers.
 
In a [[tagged architecture]], a number of bits in every word of memory are reserved to act as a tag.  Tagged architectures, such as the [[Lisp machine]]s, often have hardware support for interpreting and processing tagged pointers.
 
[[GNU C Library|GNU libc]] malloc() always returns 8-byte aligned memory addresses.  Larger alignment values can be obtained with posix_memalign().<ref>{{man|3|posix_memalign|Linux}}</ref>
 
==Examples==
===Example 1===
In the following C code, we see 0 used to indicate a null pointer:
 
<source lang="c">
void optionally_return_a_value (int* pOptionalReturnValue) {
  // ...
  if (pOptionalReturnValue)
    *pOptionalReturnValue = 01;
}
</source>
 
===Example 2===
Here, the programmer has provided a global variable, whose address is then used as a sentinel:
<source lang="c">
node g_sentinel;
#define SENTINEL &g_sentinel
 
void do_something_to_a_node (node* p) {
  if (p == NULL) {
    // do something
  } else if (p == SENTINEL) {
    // do something else
  } else {
    // treat p as a valid pointer to a node
  }
}
</source>
 
===Example 3===
Assume we have a data structure <code>table_entry</code> that is always aligned to a 16 byte boundary. In other words, the least significant 4 bits of a table entry's address are always 0 (<math>2^4 = 16</math>).  We could use these 4 bits to mark the table entry with extra information.  For example, bit 0 might mean read only, bit 1 might mean dirty (the table entry needs to be updated), and so on.
 
If pointers are 16-bit values, then:
* <code>0x3421</code> is a read-only pointer to the <code>table_entry</code> at address <code>0x3420</code>
* <code>0xf472</code> is a pointer to a dirty <code>table_entry</code> at address <code>0xf470</code>
 
==Advantages==
The major advantage of tagged pointers is that they take up less space than a pointer along with a separate tag field. This can be especially important when a pointer is a return value from a [[Function (computer science)|function]].  It can also be important in large tables of pointers.
 
A more subtle advantage is that by storing a tag in the same place as the pointer, it is often possible to guarantee the [[Linearizability|atomicity]] of an operation that updates both the pointer and its tag without external [[synchronization]] mechanisms.  This can be an extremely large performance gain, especially in operating systems.
 
==Disadvantages==
Tagged pointers have some of the same difficulties as [[xor linked list]]s, although to a lesser extent.  For example, not all [[debugger]]s will be able to properly follow tagged pointers; however, this is not an issue for a debugger that is designed with tagged pointers in mind.
 
The use of 0 to represent a null pointer does not suffer from these disadvantages: it is pervasive, and most programming languages treat 0 as a special null value. It has thoroughly proven its robustness.  Usually when "tagged pointers" are spoken of, this common use is excluded.
 
==References==
{{Reflist|2}}
 
{{DEFAULTSORT:Tagged Pointer}}
[[Category:Programming constructs]]

Latest revision as of 21:45, 15 December 2014

Hi there, I am Alyson Pomerleau and I think it sounds fairly good when you say it. Credit authorising is how he makes money. To perform lacross is something I really appreciate doing. Mississippi is where her house is but her husband wants them to move.

my site ... free tarot readings; www.january-yjm.com,