Skip to content
VecInitWithDeepCopyT

VecInitWithDeepCopyT

VecInitWithDeepCopyT

Description

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

Parameters

Name Direction Description
v in Variable or type of a vector to be initialized.
ci in Copy init method.
cd in Copy 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)

Usage examples (Cross-references)
    
    void init_char_ptr_vec(CharPtrVec *vec) {
        *vec = VecInitWithDeepCopyT(*vec, char_ptr_copy_init, char_ptr_deinit);
    }
                if (*offset + 4 <= size) {
                    // Create a temporary vector for merging
                    CharPtrVec temp = VecInitWithDeepCopyT(temp, char_ptr_copy_init, char_ptr_deinit);
    
                    // Add some strings to temp
                if (*offset + 4 <= size) {
                    // Create a temporary vector for cloning
                    CharPtrVec temp = VecInitWithDeepCopyT(temp, char_ptr_copy_init, char_ptr_deinit);
    
                    // Add some strings to temp
    
    void init_str_vec(StrVec *vec) {
        *vec = VecInitWithDeepCopyT(*vec, NULL, StrDeinit);
    }
                if (*offset + 4 <= size) {
                    // Create a temporary vector for merging
                    StrVec temp = VecInitWithDeepCopyT(temp, NULL, StrDeinit);
    
                    // Add some strings to temp
                if (*offset + 4 <= size) {
                    // Create a temporary vector for cloning
                    StrVec temp = VecInitWithDeepCopyT(temp, NULL, StrDeinit);
    
                    // Add some strings to temp
        result.analysis_id  = 999;
        result.sha256       = StrInitFromZstr("abc123");
        result.tags         = VecInitWithDeepCopyT(result.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.binary_name  = StrInit();
        result.sha256       = StrInit();
        result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit);
        result.created_at   = StrInit();
        result.model_name   = StrInit();
        product.name          = StrInitFromZstr("Laptop");
        product.price         = 999.99;
        product.tags          = VecInitWithDeepCopyT(product.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);
Last updated on