Skip to content

Commit

Permalink
add capacity function to query the underlying allocated space
Browse files Browse the repository at this point in the history
  • Loading branch information
abraunst committed Jan 30, 2019
1 parent e405d2e commit 3921dfa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,17 @@ function sizehint!(a::Vector, sz::Integer)
a
end

"""
capacity(s)
Returns the allocated buffer capacity of s.
"""
function capacity end

function capacity(a::Vector)
return ccall(:jl_array_capacity, Csize_t, (Any,), a)
end

"""
pop!(collection) -> item
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ export
any!,
any,
firstindex,
capacity,
collect,
count,
delete!,
Expand Down
5 changes: 5 additions & 0 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,11 @@ JL_DLLEXPORT void jl_array_sizehint(jl_array_t *a, size_t sz)
}
}

JL_DLLEXPORT size_t jl_array_capacity(jl_array_t *a)
{
return a->maxsize;
}

JL_DLLEXPORT jl_array_t *jl_array_copy(jl_array_t *ary)
{
size_t elsz = ary->elsize;
Expand Down

0 comments on commit 3921dfa

Please sign in to comment.