How to free memory used in a vector<float>

S

silverburgh.meryl

Hi,

I have a class attribute 'vector<float>'

class MyClass {
public:
virtual ~MyClass();
private:
vector<float> aVector;
};


I would like to know what do I need to do to free the memory used in
'aVector'.
I think i need to do 'clear()' to free each float in the aVector, but
do I need to anything specifically to free the vector itself.

MyClass::~MyClass() {
aVector.clear();
}

Thank you.
 
J

Jerry Coffin

Hi,

I have a class attribute 'vector<float>'

class MyClass {
public:
virtual ~MyClass();
private:
vector<float> aVector;
};


I would like to know what do I need to do to free the memory used in
'aVector'.
I think i need to do 'clear()' to free each float in the aVector, but
do I need to anything specifically to free the vector itself.

MyClass::~MyClass() {
aVector.clear();
}

As far as destroying the vector goes, you don't have to do anything --
the vector gets destroyed when the MyClass object is destroyed, and
vector's dtor releases whatever memory it's using.
 
M

Markus Moll

Hi
Why are you using 'float' instead of 'double'?

'double' is likely more efficient (or just as efficient)

That depends. E.g., Intel recommends using the smallest possible data-type
so that MMX/SSE can be used more efficiently.

Markus
 
J

Juha Nieminen

Markus said:
Hi


That depends. E.g., Intel recommends using the smallest possible data-type
so that MMX/SSE can be used more efficiently.

Also since 'double' takes twice as much space as 'float', some caching
and other memory issues might also kick in in some situations, making it
less efficient (especially if the vector is very large).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top