prg_vector_copy()

Abstract

Creates a new vector that is a copy of the original vector.

Syntax

prg_vector_copy (orig_vector_ptr)
Argument Type Description
orig_vector_ptr PrgT_Vector * pointer to the original vector

Return Type

PrgT_Vector *

Pointer to the copy vector that is created by this function

prg_vector.h

Details

Two styles of copying are supported, and the style used depends on whether or not a non-NIL procedure is registered within the vector (see prg_vector_create()). If a copy procedure is registered, then it is used to generate copies of each of the elements in the original vector and store them in the new vector. The element pointers in the new vector are returned by the copy handler, so if new memory is allocated for each element (as is typically the case), then the two vectors will contain different pointers.

If the registered copy procedure is NIL, then the pointers are simply copied over from the original vector. Thus, the two vectors are identical, with elements pointing to the same memory. This approach may be useful if the copy vector is to be manipulated (e.g., by deleting or reordering elements) for temporary purposes (e.g., displaying elements graphically), and if you want to preserve the content of the original vector.

One problem that frequently arises when creating identical vectors (i.e., using the second method) occurs when one of the vectors is destroyed using a “deep destroy” (see prg_vector_destroy()). In this case, the remaining vector still maintains element pointers, but these pointers reference deallocated memory. Dereferencing these pointers or deallocating the memory redundantly can lead to behavioral bugs or program crashes.

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com