VecInitWithDeepCopyT

Table of Contents

VecInitWithDeepCopyT

Description

Initialize given vector. Default alignment is 1 It is mandatory to initialize vectors before use. Not doing so is undefined behaviour.

Parameters

NameDirectionDescription
vinVariable or type of a vector to be initialized.
ciinCopy init method.
cdinCopy deinit method.

Usage example (from documentation)

    bool DataInitClone(Data* dst, Data* src) { /* cloning logic...*/ }
    void DataDeinit(Data* d) { /* deinit logic... don't free "d" */ }

    void SomeInterestingFn(DataVec* data_vec) {
        *data_vec = VecInitWithDeepCopyT(data, DataInitClone, DataDeinit);

        // use vector
    }

Usage example (Cross-references)

    product.name          = StrInitFromZstr("Laptop");
    product.price         = 999.99;
    product.tags          = VecInitWithDeepCopyT(product.tags, NULL, StrDeinit);
    
    // Create strings and push them properly
    SimpleProduct product = {0};
    product.name          = StrInit();
    product.tags          = VecInitWithDeepCopyT(product.tags, NULL, StrDeinit);
    
    JR_OBJ(si, {
    result.analysis_id  = 999;
    result.sha256       = StrInitFromZstr("abc123");
    result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit);
    
    // Create strings and push them properly
    original.config.timeout    = 30;
    original.config.log_level  = StrInitFromZstr("INFO");
    original.config.features   = VecInitWithDeepCopyT(original.config.features, NULL, StrDeinit);
    
    // Create strings and push them properly
    parsed.config.timeout    = 0;
    parsed.config.log_level  = StrInit();
    parsed.config.features   = VecInitWithDeepCopyT(parsed.config.features, NULL, StrDeinit);
    parsed.numbers           = VecInitT(parsed.numbers);
    parsed.flags             = VecInitT(parsed.flags);
    result.binary_name  = StrInit();
    result.sha256       = StrInit();
    result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit);
    result.created_at   = StrInit();
    result.model_name   = StrInit();

Share :

Related Posts

VecInitT

VecInitT Description Initialize given vector. Default alignment is 1 It is mandatory to initialize vectors before use. Not doing so is undefined behaviour.

Read More

BitVecResize

BitVecResize Description Reu64 bitvector to hold exactly n bits. May grow or shrink the bitvector.

Read More

BitVecLen

BitVecLen Description Get number of bits currently in bitvector.

Read More