Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to free memory used in a vector<float>

Reply
Thread Tools

How to free memory used in a vector<float>

 
 
silverburgh.meryl@gmail.com
Guest
Posts: n/a
 
      07-16-2008
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.

 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      07-16-2008
In article <0ea398d4-14b5-41dd-9409-aa681cb74c43
@y38g2000hsy.googlegroups.com>, http://www.velocityreviews.com/forums/(E-Mail Removed) says...
> 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.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
 
Markus Moll
Guest
Posts: n/a
 
      07-16-2008
Hi

Alf P. Steinbach wrote:

> 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

 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      07-18-2008
Markus Moll wrote:
> Hi
>
> Alf P. Steinbach wrote:
>
>> 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.


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).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How memory function free() knows how much memory to free. Panduranga Chary C Programming 2 12-27-2007 06:01 AM
How to find the total and free memory available in RAM. and used & free space available in each disk? kathirvel.com@gmail.com Java 1 11-02-2006 02:31 PM



Advertisments