[ios.base.storage]

# 31 Input/output library [[input.output]](./#input.output)

## 31.5 Iostreams base classes [[iostreams.base]](iostreams.base#ios.base.storage)

### 31.5.2 Class ios_base [[ios.base]](ios.base#storage)

#### 31.5.2.6 Storage functions [ios.base.storage]

[ð](#lib:xalloc,ios_base)

`static int xalloc();
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1433)

*Returns*: *index*++[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1438)

*Remarks*: Concurrent access to this function by multiple threads does not result in a[data race](intro.multithread#def:data_race "6.10.2 Multi-threaded executions and data races [intro.multithread]")[.](#2.sentence-1)

[ð](#lib:iword,ios_base)

`long& iword(int idx);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1450)

*Preconditions*: idx is a value obtained by a call to xalloc[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1454)

*Effects*: If *iarray* is a null pointer, allocates an array oflong of unspecified size and stores a pointer to its first element in*iarray*[.](#4.sentence-1)

The function then extends the array pointed at by*iarray* as necessary to include the element*iarray*[idx][.](#4.sentence-2)

Each newly allocated element of the array is initialized to zero[.](#4.sentence-3)

The reference returned is invalid after any other operation on the
object[.](#4.sentence-4)[260](#footnote-260 "An implementation is free to implement both the integer array pointed at by iarray and the pointer array pointed at by parray as sparse data structures, possibly with a one-element cache for each.")

However, the value of the storage referred to is retained, so
that until the next call tocopyfmt,
callingiword with the same index yields another reference to the same value[.](#4.sentence-5)

If the function fails[261](#footnote-261 "For example, because it cannot allocate space.") and*this is a base class subobject of abasic_ios<> object or subobject, the effect is equivalent to callingbasic_ios<>​::​setstate(badbit) on the derived object (which may throwfailure)[.](#4.sentence-6)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1491)

*Returns*: On success*iarray*[idx][.](#5.sentence-1)

On failure, a validlong& initialized to 0[.](#5.sentence-2)

[ð](#lib:pword,ios_base)

`void*& pword(int idx);
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1506)

*Preconditions*: idx is a value obtained by a call to xalloc[.](#6.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1510)

*Effects*: If *parray* is a null pointer, allocates an array of
pointers to void of unspecified size and stores a pointer to
its
first element in *parray*[.](#7.sentence-1)

The function then extends the array
pointed at by *parray* as necessary to include the element*parray*[idx][.](#7.sentence-2)

Each newly allocated element of the array is initialized to a null
pointer[.](#7.sentence-3)

The reference returned is invalid after any other operation on the
object[.](#7.sentence-4)

However, the value of the storage referred to is retained, so
that until the next call tocopyfmt,
callingpword with the same index yields another reference to the same value[.](#7.sentence-5)

If the function fails[262](#footnote-262 "For example, because it cannot allocate space.") and*this is a base class subobject of abasic_ios<> object or subobject, the effect is equivalent to callingbasic_ios<>​::​setstate(badbit) on the derived object (which may throwfailure)[.](#7.sentence-6)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1542)

*Returns*: On successparray[idx][.](#8.sentence-1)

On failure a validvoid*& initialized to 0[.](#8.sentence-2)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1550)

*Remarks*: After a subsequent call topword(int) for the same object, the earlier return value may no longer be valid[.](#9.sentence-1)

[260)](#footnote-260)[260)](#footnoteref-260)

An implementation is free to implement both the integer
array pointed at by *iarray* and the pointer array pointed at by*parray* as sparse data structures, possibly with a one-element
cache for each[.](#footnote-260.sentence-1)

[261)](#footnote-261)[261)](#footnoteref-261)

For example, because it cannot allocate space[.](#footnote-261.sentence-1)

[262)](#footnote-262)[262)](#footnoteref-262)

For example, because it cannot allocate space[.](#footnote-262.sentence-1)
