Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Dope vector
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Purpose== Dope vectors are most commonly used to describe [[Array data structure|arrays]], which commonly store multiple instances of a particular datatype as a contiguous block of memory. For example, an array containing 100 elements, each of which occupies 32 bytes, requires 100 Γ 32 bytes. By itself, such a memory block has no place to keep track of how large the array (or other object) is overall, how large each element within it is, or how many elements it contains. A dope vector is a place to store such information. Dope vectors can also describe [[Record (computer science)|structures]] which may contain arrays or variable elements. If such an array is stored contiguously, with the first byte at memory location ''M'', then its last byte is at location {{nowrap|''M'' + 3199}}. A major advantage of this arrangement is that locating item ''N'' is easy: it begins at location {{nowrap|''M'' + (''N'' Γ 32)}}. Of course, the value 32 must be known (this value is commonly called the "stride" of the array or the "width" of the array's elements). Navigating an array data structure using an index is called [[Dead reckoning#Computer science|dead reckoning]]. This arrangement, however (without adding dope vectors) means that having the location of item N is not enough to discover the index N itself; or the stride; or whether there are elements at {{nowrap|''N'' β 1}} or {{nowrap|''N'' + 1}}. For example, a function or method may iterate over all the items in an array and pass each one to another function or method, which does not know the item is part of an array at all, much less where or how large the array is. Without a dope vector, even knowing the address of the entire array does not tell you how big it is. This is important because writing to the {{nowrap|''N'' + 1}} element in an array that only contains ''N'' elements, will likely destroy some other data. Because many programming languages treat character strings as a kind of array, this leads directly to the infamous [[buffer overflow]] problem. A dope vector reduces these problems by storing a small amount of [[metadata]] along with an array (or other object). With dope vectors, a compiler can easily (and optionally) insert code that prevents accidentally writing beyond the end of an array or other object. Alternatively, the programmer can access the dope vector when desired, for safety or other purposes.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)