Dictionary Definition
restrict
Verb
2 place under restrictions; limit access to;
"This substance is controlled" [ant: derestrict]
3 place limits on (extent or access); "restrict
the use of this parking lot"; "limit the time you can spend with
your friends" [syn: restrain, trammel, limit, bound, confine, throttle]
4 make more specific; "qualify these remarks"
[syn: qualify]
User Contributed Dictionary
English
Etymology
From Latin perfect passive participle restrictus, from verb restringere, from prefix re- again, + verb stringere.Pronunciation
-
- Rhymes: -ɪkt
Verb
Translations
- Arabic:
- Chinese: 限制 (xiànzhì)
- Dutch: beperken
- Finnish: rajoittaa, pysyä jossakin
- French: restreindre
- German: beschränken
- Italian: restringere
- Japanese: 制限する (せいげんする, seigen suru)
- Korean: 제한하다 (jehanhada)
- Portuguese: restringir
- Russian: ограничивать (ograníčivat’)
- Spanish: restringir
- Swedish: inskränka
Synonyms
Extensive Definition
In the C
programming language, as of the C99 standard, restrict is a
keyword which may be used when declaring pointers.
The restrict keyword is a message from the programmer to the
compiler saying 'this
is the only pointer to that memory block'. The data pointed to by a
pointer declared with the restrict qualifier may not be pointed to
by any other pointer, or strange runtime behavior may result.
Optimization
If the compiler knows that there is only one
pointer to a memory block, it can produce better optimised code.
The following example makes it clear:
void UpdatePtrs(size_t* ptrA, size_t* ptrB,
size_t* val) In the above code, the pointers ptrA , ptrB, val might
refer to the same memory
location, so the compiler will generate a less optimal code
:
load R1 ← *val ; Load the value of val pointer
load R2 ← *ptrA ; Load the value of ptrA ponter add R2 += R1 ;
Perform Addition set R2 → *ptrA ; Update the value of ptrA pointer;
Because ptrA may point to val. load R1 ← *val load R2 ← *ptrB add
R2 += R1 set R2 → *ptrB
However if the restrict keyword is used and the
above function is declared as void UpdatePtrs(size_t* restrict
ptrA, size_t* restrict ptrB, size_t* restrict val) then the
compiler is allowed to assume that ptrA , ptrB, val point to
different locations and updating one pointer will not affect the
other pointers. The programmer, not the compiler, is responsible
for ensuring that the pointers do not point to different
locations.
Now the compiler can generate more optimal code
as follows:
load R1 ← *val load R2 ← *ptrA load R3 ← *ptrB
add R2 += R1 add R3 += R1 set R2 → *ptrA set R3 → *ptrB
Note that the above assembly code is more optimal
and the val is loaded once.
Another example is of memcpy. The two pointers
used as arguments to memcpy(void*, void*, nbytes) are declared with
restrict, which tells the compiler of the memcpy function that the
two data areas do not overlap. This allows the compiler to produce
a faster memcpy function. A programmer might send the same pointer
as both arguments, in which case behavior of the memcpy function is
undefined.
External links
- Demystifying The Restrict Keyword: explanation and examples of use
Synonyms, Antonyms and Related Words
abate,
adjust to, allocate,
allot, alter, appoint, appropriate to,
assign, assign to,
assuage, bar, be into, be strong in, bind, bottle up, bound, box, box in, box up, cage, check, circumscribe, cloister, condition, confine, constrain, constrict, contain, contract, coop, coop in, coop up, copyright, cork up, cramp, crib, delimit, delimitate, demarcate, destine, detail, detain, diminish, discipline, draw in, draw the
line, earmark, encage, enclose, fate, feature, fence in, follow, go in, go in for,
hedge, hedge about,
hem, hem in, hold, hold in custody, hold in
restraint, immure,
impede, impound, inhibit, keep from spreading,
keep in, keep in custody, keep in detention, keep within bounds,
leaven, limit, localize, lot, major in, make assignments,
mark off, mark out for, mew,
mew up, minor in, mitigate, moderate, modify, modulate, narrow, ordain, palliate, patent, pen, pen up, portion off, pound, pursue, qualify, rail in, reduce, register, regulate, regulate by, reserve, restrain, restrict to, scant, schedule, seal up, season, set, set apart, set aside, set
conditions, set limits, set off, shackle, shrink, shut in, shut up,
snape, soften, specialize, specialize in,
stint, straiten, tag, taper, temper, tie, tighten, wall in