Alternate Entry Name: ADD.VE
B: vector = addvec( vector [,addlen [,oldlen] ]);
/* C users use realloc */
ADDVEC, whose name is somewhat misleading, "adds" a total of "addlen" words to the length of a given vector. It does this by calling GETVEC to allocate a new larger vector, copying the old vector into the new, and then calling RLSEVEC to release the old vector's memory.
Note that if you have pointers into the old vector, it is extremely unwise to call ADDVEC unless you are prepared to reset your pointers to the proper locations in the new vector.
The value which ADDVEC returns is a word whose lower half is a pointer to the location of the new vector, and whose upper half contains the allocated length of the new vector. Thus if you make a number of calls to ADDVEC to grow the same vector, you need only specify "oldlen" once; on subsequent calls, the "oldlen" value will be contained in the vector pointer itself.
Since ADDVEC calls RLSEVEC, using ADDVEC to increase the length of auto vectors or externally declared "static" vectors will probably lead to disaster.
Copyright © 1996, Thinkage Ltd.