Learn R Programming

cppcontainers (version 1.0.4)

capacity: Get container capacity

Description

Get the capacity of a CppVector.

Usage

capacity(x)

Value

Returns a numeric.

Arguments

x

A CppVector object.

Details

The capacity is the space reserved for the vector, which can exceed its size. Additional capacity ensures that the vector can be extended efficiently, without having to reallocate its current elements to a new memory location.

See Also

reserve, shrink_to_fit, size.

Examples

Run this code
v <- cpp_vector(4:9)
v
# 4 5 6 7 8 9

capacity(v)
# [1] 6

reserve(v, 20)
size(v)
#[1] 6
capacity(v)
# [1] 20

v
# 4 5 6 7 8 9

Run the code above in your browser using DataLab