StrReserve
Description
Reserve enough capacity to fit at least n characters without further allocation. Does not change the string length. See VecReserve for the full SUCCESS/FAILURE contract.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Io.c:1166:
if (file_len > 0) {
StrReserve(&buffer, (u64)file_len);
i64 got = FileRead(file, StrBegin(&buffer), (u64)file_len);
if (got < 0) {- In
Str.c:101:
}
if (!StrReserve(out, len)) {
return false;
}- In
BitVec.c:898:
}
if (!StrReserve(out, bv->length + 1)) {
return false;
}- In
ProcMaps.c:213:
while (true) {
u64 grown_to = StrLen(raw) + CHUNK + 1;
if (!StrReserve(raw, grown_to))
return false;
i64 n = FileRead(f, StrEnd(raw), CHUNK);- In
ProcMaps.c:284:
out->entries = VecInitT(out->entries, alloc);
if (len) {
if (!StrReserve(&out->raw, len + 1)) {
ProcMapsDeinit(out);
return false;- In
Ops.c:625:
Str a = StrInitFromCstr("ab", 2, &alloc);
StrReserve(&a, 8);
// Plant bytes beyond `a`'s logical length (still inside capacity 8) that
// exceed the corresponding bytes of `b`. Only the mutant ever reads them.
- In
Memory.c:26:
// Reserve more space than needed
StrReserve(&s, 100);
// Add some data
- In
Memory.c:101:
// Test StrReserve function
bool test_str_reserve(void) {
WriteFmt("Testing StrReserve\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Memory.c:108:
// Reserve more space
StrReserve(&s, 100);
// Capacity should now be at least 100
- In
Memory.c:117:
// Reserve less space (should be a no-op)
StrReserve(&s, 50);
// Capacity should still be at least 100
Last updated on