| Pointer Swizzling |
Article Index for Pointer |
Website Links For Pointer |
Information AboutPointer Swizzling |
| CATEGORIES ABOUT POINTER SWIZZLING | |
| memory management | |
|
A related meaning is found in applications. EXAMPLE For example, suppose we have the following Linked List data structure: record node { ''int'' data ''node'' next } We can easily create a linked list data structure in memory using such an object, but when we attempt to save it to disk we run into trouble. Directly saving the pointer values won't work on most architectures, because the next time we load it the memory positions the nodes now use may be in use by other data. One way of dealing with this is to assign a number to each node and then ''unswizzle'' the pointers by turning them into a field indicating the number of the next node: record node_saved { ''int'' number ''int'' data ''int'' number_of_next } We can save these records to disk in any order, and no information will be lost. Alternatives include saving the file offset of the next node or a number indicating its position in the sequence of saved records. When we go to load these nodes, however, we quickly discover that attempting to find a node based on its number is cumbersome and inefficient. We'd like our original data structure back so we can simply follow next pointers to traverse the list. To do this, we perform ''pointer swizzling'', finding the address of each node and turning the ''number_of_next'' fields back into direct pointers to the right node. METHODS OF UNSWIZZLING There are a potentially unlimited number of forms into which a pointer can be unswizzled, but some of the most popular include:
METHODS OF SWIZZLING Swizzling in the general case can be complicated. The reference Graph of pointers might contain an arbitrary number of Cycle s; this complicates maintaining a mapping from the old unswizzled values to the new addresses. Associative Array s are useful for maintaining the mapping, while algorithms such as Breadth-first Search help to traverse the graph, although both of these require extra storage. Various Serialization Libraries provide general swizzling systems. In many cases, however, swizzling can be performed with simplifying assumptions, such as a Tree or List structure of references. REFERENCES
EXTERNAL LINKS
|
|
|