[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why vectors?
On Tue, 12 Aug 2008, Per Bothner wrote:
creation of a new fixed-length vector is O(1).
To be nit-picky: I don't see how that is possible.
After all, the member for the vector does at least
have to br zeroed out.
Of course the constant factor is usually very low.
it doesnt have to be zeroed if the gc sets everything to the undefined
when dead. vectors dont autoinitialise to zero, the initialise to
so its just a matter of creating a single header on top of sufficient
Whether an element is set to "zero" or "the undefined value" it
takes just as long. Whether this is done when allocating the
object, or when collecting whatever was previously there - it
still has to be done, and it's still O(N). And you can't reuse
whatever junk happens to be in those memory cells, since that
would confuse the gc.
Imagine allocating an array of a million elements, and you need to
get fresh pages from the OS. The OS will have zero'd out those
pages (at least a modern desktop or server OS), for safety reasons.
And doing so is proportional to the size of the vector.