This article needs additional citations for verification .(December 2009) |
In computer programming, the stride of an array (also referred to as increment, pitch or step size) is the number of locations in memory between beginnings of successive array elements, measured in bytes or in units of the size of the array's elements. The stride cannot be smaller than the element size but can be larger, indicating extra space between elements.
An array with stride of exactly the same size as the size of each of its elements is contiguous in memory. Such arrays are sometimes said to have unit stride. Unit stride arrays are sometimes more efficient than non-unit stride arrays, but non-unit stride arrays can be more efficient for 2D or multi-dimensional arrays, depending on the effects of caching and the access patterns used [ citation needed ]. This can be attributed to the principle of locality, specifically spatial locality.
Arrays may have a stride larger than their elements' width in bytes in at least two cases:
Some languages allow arrays of structures to be treated as overlapping parallel arrays with non-unit stride:
#include<stdio.h>structMyRecord{intvalue;char*text;};/** Print the contents of an array of ints with the given stride. Note that size_t is the correct type, as int can overflow. */voidprint_some_ints(constint*arr,intlength,size_tstride){inti;printf("Address\t\tValue\n");for(i=0;i<length;++i){printf("%p\t%d\n",arr,arr[0]);arr=(int*)((unsignedchar*)arr+stride);}}intmain(void){intints[100]={0};structMyRecordrecords[100]={0};print_some_ints(&ints[0],100,sizeofints[0]);print_some_ints(&records[0].value,100,sizeofrecords[0]);return0;}
This idiom is a form of type punning.
Some languages like PL/I or Fortran allow what is known as an array cross-section, which selects certain columns or rows from a larger array. [1] : p.262 For example, if a two-dimensional array is declared as
declaresome_array(12,2)fixed;
an array of one dimension consisting only of the second column may be referenced as
some_array(*,2)
Non-unit stride is particularly useful for images. It allows for creating subimages without copying the pixel data. Java example:
publicclassGrayscaleImage{privatefinalintwidth,height,widthStride;/** Pixel data. Pixel in single row are always considered contiguous in this example. */privatefinalbyte[]pixels;/** Offset of the first pixel within pixels */privatefinalintoffset;/** Constructor for contiguous data */publicImage(intwidth,intheight,byte[]pixels){this.width=width;this.height=height;this.pixels=pixels;this.offset=0;this.widthStride=width;}/** Subsection constructor */publicImage(intwidth,intheight,byte[]pixels,intoffset,intwidthStride){this.width=width;this.height=height;this.pixels=pixels;this.offset=offset;this.widthStride=widthStride;}/** Returns a subregion of this Image as a new Image. This and the new image share the pixels, so changes to the returned image will be reflected in this image. */publicImagecrop(intx1,inty1,intx2,inty2){returnnewImage(x2-x1,y2-y1,pixels,offset+y1*widthStride+x1,widthStride);}/** Returns pixel value at specified coordinate */publicbytegetPixelAt(intx,inty){returnpixels[offset+y*widthStride+x];}}
C is a general-purpose programming language. It was created in the 1970s by Dennis Ritchie and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems code, device drivers, and protocol stacks, but its use in application software has been decreasing. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.
In computer science, bogosort is a sorting algorithm based on the generate and test paradigm. The function successively generates permutations of its input until it finds one that is sorted. It is not considered useful for sorting, but may be used for educational purposes, to contrast it with more efficient algorithms.
The BMP file format or bitmap, is a raster graphics image file format used to store bitmap digital images, independently of the display device, especially on Microsoft Windows and OS/2 operating systems.
In computer science, a lookup table (LUT) is an array that replaces runtime computation with a simpler array indexing operation, in a process termed as direct addressing. The savings in processing time can be significant, because retrieving a value from memory is often faster than carrying out an "expensive" computation or input/output operation. The tables may be precalculated and stored in static program storage, calculated as part of a program's initialization phase (memoization), or even stored in hardware in application-specific platforms. Lookup tables are also used extensively to validate input values by matching against a list of valid items in an array and, in some programming languages, may include pointer functions to process the matching input. FPGAs also make extensive use of reconfigurable, hardware-implemented, lookup tables to provide programmable hardware functionality. LUTs differ from hash tables in a way that, to retrieve a value with key , a hash table would store the value in the slot where is a hash function i.e. is used to compute the slot, while in the case of LUT, the value is stored in slot , thus directly addressable.
Perlin noise is a type of gradient noise developed by Ken Perlin in 1983. It has many uses, including but not limited to: procedurally generating terrain, applying pseudo-random changes to a variable, and assisting in the creation of image textures. It is most commonly implemented in two, three, or four dimensions, but can be defined for any number of dimensions.
The syntax of the C programming language is the set of rules governing writing of software in C. It is designed to allow for programs that are extremely terse, have a close relationship with the resulting object code, and yet provide relatively high-level data abstraction. C was the first widely successful high-level language for portable operating-system development.
In computer science, a pointer is an object in many programming languages that stores a memory address. This can be that of another value located in computer memory, or in some cases, that of memory-mapped computer hardware. A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer. As an analogy, a page number in a book's index could be considered a pointer to the corresponding page; dereferencing such a pointer would be done by flipping to the page with the given page number and reading the text found on that page. The actual format and content of a pointer variable is dependent on the underlying computer architecture.
In computer programming, foreach loop is a control flow statement for traversing items in a collection. foreach is usually used in place of a standard for loop statement. Unlike other for loop constructs, however, foreach loops usually maintain no explicit counter: they essentially say "do this to everything in this set", rather than "do this x times". This avoids potential off-by-one errors and makes code simpler to read. In object-oriented languages, an iterator, even if implicit, is often used as the means of traversal.
In the C programming language, struct is the keyword used to define a composite, a.k.a. record, data type – a named set of values that occupy a block of memory. It allows for the different values to be accessed via a single identifier, often a pointer. A struct can contain other data types so is used for mixed-data-type records. For example a bank customer struct might contains fields: name, address, telephone, balance.
In computing, an uninitialized variable is a variable that is declared but is not set to a definite known value before it is used. It will have some value, but not a predictable one. As such, it is a programming error and a common source of bugs in software.
In computer graphics, the Liang–Barsky algorithm is a line clipping algorithm. The Liang–Barsky algorithm uses the parametric equation of a line and inequalities describing the range of the clipping window to determine the intersections between the line and the clip window. With these intersections it knows which portion of the line should be drawn. So this algorithm is significantly more efficient than Cohen–Sutherland. The idea of the Liang–Barsky clipping algorithm is to do as much testing as possible before computing line intersections.
In the C programming language, data types constitute the semantics and characteristics of storage of data elements. They are expressed in the language syntax in form of declarations for memory locations or variables. Data types also determine the types of operations or methods of processing of data elements.
Data structure alignment is the way data is arranged and accessed in computer memory. It consists of three separate but related issues: data alignment, data structure padding, and packing.
sizeof is a unary operator in the programming languages C and C++. It generates the storage size of an expression or a data type, measured in the number of char-sized units. Consequently, the construct sizeof (char) is guaranteed to be 1. The actual number of bits of type char is specified by the preprocessor macro CHAR_BIT, defined in the standard include file limits.h. On most modern computing platforms this is eight bits. The result of sizeof has an unsigned integer type that is usually denoted by size_t.
XImage is the X client side storage mechanism for an X Window System pixel map. The structure of an XImage as defined by the X Window core protocol is the following:
The C and C++ programming languages are closely related but have many significant differences. C++ began as a fork of an early, pre-standardized C, and was designed to be mostly source-and-link compatible with C compilers of the time. Due to this, development tools for the two languages are often integrated into a single product, with the programmer able to specify C or C++ as their source language.
In computer science, a type punning is any programming technique that subverts or circumvents the type system of a programming language in order to achieve an effect that would be difficult or impossible to achieve within the bounds of the formal language.
ALGOL 68RS is the second ALGOL 68 compiler written by I. F. Currie and J. D. Morrison, at the Royal Signals and Radar Establishment (RSRE). Unlike the earlier ALGOL 68-R, it was designed to be portable, and implemented the language of the Revised Report.
C struct data types may end with a flexible array member with no specified size:
In computing, interleaving of data refers to the interspersing of fields or channels of different meaning sequentially in memory, in processor registers, or in file formats. For example, for coordinate data,