Skip to content

BufResize

Description

Set b’s length to exactly n bytes, growing the backing store if necessary. New bytes are zero-initialized; existing bytes past n are dropped.

Success

Returns true; b->length == n. b->data may have moved when growing.

Failure

Returns false if the underlying allocator fails to grow the buffer; *b is unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
        MemCopy(BufData(&copy), data, data_size);
        BufResize(&copy, (size)data_size);
        return PeOpenFromMemory(out, &copy);
    }
        }
        MemCopy(BufData(&copy), data, data_size);
        BufResize(&copy, (size)data_size);
        return PdbOpenFromMemory(out, &copy);
    }
        }
        MemCopy(BufData(&copy), data, data_size);
        BufResize(&copy, (size)data_size);
        return MachoOpenFromMemory(out, &copy);
    }
        }
        MemCopy(BufData(&copy), data, data_size);
        BufResize(&copy, (size)data_size);
        // Hand `&copy` to the L-form -- it consumes the local and zeros
        // it. The local goes out of scope right after.
        };
        Buf  src = BufInit(alloc_base);
        bool ok  = BufResize(&src, N);
        for (i32 i = 0; i < N; ++i) {
            BufData(&src)[i] = (u8)('A' + (i % 26));
    
        Buf  in = BufInit(alloc_base);
        bool ok = BufResize(&in, 5);
        MemCopy(BufData(&in), "12345", 5);
        }
        MemCopy(BufData(&in), sblob, sizeof(sblob));
        BufResize(&in, (size)sizeof(sblob));
    
        Pdb  pdb;
Last updated on