resize
void resize(var self, size_t n);
Resize to some size n
, perhaps reserving some resource for object self
.
Usage
var x = new(Array, Int);
resize(x, 10000); /* Reserve space in Array */
for (size_t i = 0; i < 10000; i++) {
push(x, $I(i));
}
Usage 2
var x = new(Array, Int, $I(0), $I(1), $I(2));
resize(x, 0); /* Clear Array of items */
Object can be resized
The Resize
class can be implemented by objects which can be resized in some way. Resizing to a larger size than the current may allow for some resource or other to be preallocated or reserved. For example this class is implemented by Array
and Table
to either remove a number of items quickly or to preallocate memory space if it is known that many items are going to be added at a later date.
struct Resize {
void (*resize)(var, size_t);
};