VecInitClone
Description
Reinitialize vd as a deep clone of vs. Any current contents of vd are first deinitialized. The destination adopts vs’s copy_init / copy_deinit / alignment / allocator configuration, then all elements are deep-copied.
Parameters
| Name | Direction | Description |
|---|---|---|
vd |
out | Destination vector. Must be initialized; its current contents are released before cloning. |
vs |
in | Source vector. |
Success
Returns true. vd now holds a deep copy of every element of vs, has the same length, and carries vs’s copy_init / copy_deinit / alignment / allocator configuration. The prior contents of vd were released before the clone began.
Failure
Returns false on allocation failure during the clone. vd is left in a valid but partially-populated state (the prior contents are gone). Callers should treat vd as opaque on failure and call VecDeinit(vd) before reuse.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
VecCharPtr.c:485:
}
VecInitClone(vec, &temp);
VecDeinit(&temp);- In
VecStr.c:463:
}
VecInitClone(vec, &temp);
VecDeinit(&temp);- In
VecInt.c:397:
}
VecInitClone(vec, &temp);
VecDeinit(&temp); // Clean up temp to prevent memory leak
- In
Insert.h:1073:
#define VecMustInitClone(vd, vs) \
do { \
if (!VecInitClone((vd), (vs))) { \
LOG_FATAL("VecMustInitClone failed"); \
} \- In
Insert.h:844:
/// TAGS: Str, Clone, Init, DeepCopy
///
#define StrInitClone(strd, strs) VecInitClone((strd), (strs))
///
Last updated on