# Added initCapacity, capacity, and 2 tests\. · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/d49e0a7b90dabbf486902fa9d4a4306aede55087)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: d49e0a7b90dabbf486902fa9d4a4306aede55087

Requested commit: d49e0a7b90dabbf486902fa9d4a4306aede55087

Commit: d49e0a7b90dabbf486902fa9d4a4306aede55087

Tree: e2ac48ed25c54c6e3b13eaddb1876331cd020eec

Author: MCRusher

Committer: GitHub

## Message

```
Added initCapacity, capacity, and 2 tests.

Added Buffer.initCapcity() to buffer to allow preallocation of a block of memory to reduce future allocations. Uses the added ArrayList.initCapacity() function to achieve this.

Added Buffer.capacity() to track current usable allocation size, not counting null byte, and returning 0 if empty or created with Buffer.initNull()

Added a test for initCapacity() that shows that no further allocation is performed for an append of size smaller than or equal to capacity when initCapacity is used.

Added a test for initSize(), since it did not exist already.

Also added a comment to better explain the difference between initSize() and initCapacity()

note: forgot in the first commit but thanks to mikdusan for helping me brainstorm, through the process, and for drawing up a draft diff which I tweaked.
```

## Parents

- [10e6cde083cf9ddd1ae72850d45c25b1258d0d7e](https://git.cafe/gitcafe/zig/commit/10e6cde083cf9ddd1ae72850d45c25b1258d0d7e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/d49e0a7b90dabbf486902fa9d4a4306aede55087?format=markdown)
