Content deleted Content added
The idea of freeing resources is not specific to the Dispose pattern |
m v2.03b - Bot T20 CW#61 - WP:WCW project (Reference before punctuation) |
||
Line 13:
These handles can be used directly, by storing the value in a variable and passing it as an argument to functions that use the resource. However, it is frequently useful to abstract from the handle itself (for example, if different operating systems represent files differently), and to store additional auxiliary data with the handle, so handles can be stored as a field in a [[Record (computer science)|record]], along with other data; if this in an [[opaque data type]], then this provides [[information hiding]] and the user is abstracted from the actual representation.
For example, in [[C file input/output]], files are represented by objects of the <code>FILE</code> type (confusingly called "[[file handle]]s": these are a language-level abstraction), which stores an (operating system) handle to the file (such as a [[file descriptor]]), together with auxiliary information like I/O mode (reading, writing) and position in the stream. These objects are created by calling <code>[[C file input/output#fopen|fopen]]</code> (in object-oriented terms, a [[Constructor_(object-oriented_programming)|constructor]]), which acquires the resource and returns a pointer to it; the resource is released by calling <code>[[C file input/output#fclose|fclose]]</code> on a pointer to the <code>FILE</code> object.<ref>{{man|bd|stdio.h|SUS}}</ref>
<syntaxhighlight lang="c">
|