Skip to content

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)
    
            if (file_len > 0) {
                StrReserve(&buffer, (u64)file_len);
                i64 got = FileRead(file, StrBegin(&buffer), (u64)file_len);
                if (got < 0) {
        }
    
        if (!StrReserve(out, bv->length + 1)) {
            return false;
        }
        }
    
        if (!StrReserve(out, len)) {
            return false;
        }
        while (true) {
            u64 grown_to = StrLen(&out->raw) + CHUNK + 1;
            if (!StrReserve(&out->raw, grown_to)) {
                LOG_ERROR("ProcMapsLoad: failed to grow buffer");
                FileClose(&f);
    
        // Reserve more space than needed
        StrReserve(&s, 100);
    
        // Add some data
    // Test StrReserve function
    bool test_str_reserve(void) {
        WriteFmt("Testing StrReserve\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        // Reserve more space
        StrReserve(&s, 100);
    
        // Capacity should now be at least 100
    
        // Reserve less space (should be a no-op)
        StrReserve(&s, 50);
    
        // Capacity should still be at least 100
Last updated on