Game Development Community

The Vector Class...

by James Urquhart · in Torque Game Engine · 09/04/2004 (11:38 am) · 3 replies

Hi there,

I was just looking through the source to torque's vector class (core/tVector.h)...

I am looking for a way to delete the mArray in the vector so that the memory of the vector is properly free'd. However, the only place the code seems to do this is in the destructor.
Other times, the code only increments the size of the vector array - it does not seem to go the other way round.

I had thought the clear() function would have at least deleted the array for me, but all it seems to do is set the element count to 0!

My Vector is a static one that stays around for a while.
As far as i can tell, if i add alot of items in the vector, then "delete" all of them shortly after (e.g. with clear()), i'm going to be wasting quite a bit of memory...

Is this an oversight in the design of the Vector class?

#1
09/04/2004 (1:47 pm)
No, it's intentional. The idea is that allocating memory is expensive and Vectors are meant to deal with fairly dynamic situations. There might be a compact method, or you could add one, that would shrink it back down to the minimal size needed to hold the data in it. That would be a good candidate for HEAD.
#2
09/05/2004 (12:41 am)
Upon closer inspection, there is a compact() method that calls the VectorResize method, which should clean out the array nicely for me :)
#3
09/06/2004 (12:01 pm)
Ah, good. :)