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!
==Description== The exact set of metadata included in a dope vector varies from one language and/or operating system to another, but a dope vector for an [[array data type|array]] might contain: * a pointer to the location in memory where the array elements begin (this is normally identical to the location of the zeroth element of the array (element with all subscripts 0). (This might not be the first actual element if subscripts do not start at zero.) * the type of each array element (integer, Boolean, a particular [[Class (computer programming)|class]], etc.). * the [[Rank (computer programming)|rank of an array]]. * the extent of an array (its range of indices). (In many languages the starting index for arrays is fixed at zero, or one, but the ending index is set when the array is (re-)allocated.) * for arrays where the extent in use at a given time may change, the maximum and current extents may both be stored. * the [[stride of an array]], or the amount of memory occupied by each element of the array. A program then can refer to the array (or other dope-vector-using object) by referring to the dope vector. This is commonly automatic in [[high-level programming language|high-level language]]s. Getting to an element of the array costs a tiny bit more (commonly one instruction, which fetches the pointer to the actual data from out of the dope vector). On the other hand, doing many other common operations are easier and/or faster: * Without a dope vector, determining the number of elements in the array is impossible. Thus it is common to add an extra element to the end of an array, with a "reserved" value (such as NULL). The length can then be determined by scanning forward through the array, counting elements until this "end-marker" is reached. Of course, this makes length-checking much slower than looking up the length directly in a dope vector. * Without knowing the extent of an array, it is not possible to [[free()]] (unallocate) that memory when it is no longer needed. Thus, without dope vectors, something must store that length somewhere else. For example, asking a particular OS to allocate space for a 3200-byte array, might cause it to allocate 3204 bytes at some location M; it would then store the size in the first 4 bytes, and tell the requesting program the allocated space starts at M+4 (so that the caller will not treat the extra 4 bytes as part of the array proper). This extra data is not considered a dope vector, but achieves some of the same goals. * Without dope vectors, extra information must also be kept about the stride (or width) of array elements. In [[C (programming language)|C]], this information is handled by the compiler, which must keep track of a datatype distinction between "pointer to an array of 20-byte-wide elements", and "pointer to an array of 1000-byte-wide elements". This means that a pointer to an element in either kind of array can be incremented or decremented in order to reach the next or previous element; but it also means that array widths must be fixed at an earlier stage. Even with a dope vector, having (only) a pointer to a particular member of an array does not enable finding the position in the array, or the location of the array or the dope vector itself. If that is desired, such information can be added to each element within the array. Such per-element information can be useful, but is not part of the dope vector. Dope vectors can be a general facility, shared across multiple datatypes (not just arrays and/or strings).<ref>{{cite conference|title=The design of a template structure for a generalized data structure definition facility|first=Billy G.|last=Claybrook|conference=ICSE '76: 2nd international conference on Software engineering|location=San Francisco, California, USA|date=October 13β15, 1976|pages=408β413|publisher=IEEE Computer Society Press|url=http://dl.acm.org/citation.cfm?id=807713&CFID=799276124&CFTOKEN=88822581}}</ref>
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)