VecInitWithDeepCopyT
- Macro
- August 22, 2025
Table of Contents
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)
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
- In
RoundTrip.c:515
:
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
- In
RoundTrip.c:564
:
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();