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)

    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);
    SimpleProduct product = {0};
    product.name          = StrInit();
    product.tags          = VecInitWithDeepCopyT(product.tags, NULL, StrDeinit);
    
    JR_OBJ(si, {
    product.name          = StrInitFromZstr("Laptop");
    product.price         = 999.99;
    product.tags          = VecInitWithDeepCopyT(product.tags, NULL, StrDeinit);
    
    // Create strings and push them properly
    result.binary_name  = StrInit();
    result.sha256       = StrInit();
    result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit);
    result.created_at   = StrInit();
    result.model_name   = StrInit();
    result.analysis_id  = 999;
    result.sha256       = StrInitFromZstr("abc123");
    result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit);
    
    // Create strings and push them properly
    
    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
    
    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

Share :

Related Posts

StrIterRemainingLength

StrIterRemainingLength Description Get remaining elements left to read

Read More

IterRemainingLength

IterRemainingLength Description Get remaining length left to read this memory iterator.

Read More

IterSize

IterSize Description Get total size of this Iter object

Read More