[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Destrying and object without calling a destructor

Bruno.DiStefano

9/3/2008 3:48:00 PM

Hi All,

I have a large number of objects living in a double loop (see below,
where CYCLES and NUMBER are huge).

////////////////////////////////////////////////////////////////
for (t=0; t < CYCLES; t++)
{
for(i=0; i<NUMBER;i++)
{
MyClass[i].run(t);
}
}

////////////////////////////////////////////////////////////////

Along the way some objects should die and vanish from my execution. I
have no way of knowing which ones and I do not care. The output of my
program is an ascii file to be processed with other programs. I just
need to make sure that the objects which are supposed to die actually
die and that all memory associated to them is released, without
altering the order in which the other objects are stored. I do not
need a list. I am using and really need a vector. Given that I should
not call a destructor explicitely, what can I do?

Thank you.

Best regards

Bruno


2 Answers

Erik Wikström

9/3/2008 4:33:00 PM

0

On 2008-09-03 17:48, Bruno.DiStefano wrote:
> Hi All,

Please do not multi-post to several newsgroups, if you have to post in
more than one group you should cross-post instead.

See my reply in c.l.c++.m (when the moderators lets it through) for a
solution to your problem.

--
Erik Wikström

Zeppe

9/3/2008 5:40:00 PM

0

Bruno.DiStefano wrote:
> Hi All,
>
> I have a large number of objects living in a double loop (see below,
> where CYCLES and NUMBER are huge).
>
> ////////////////////////////////////////////////////////////////
> for (t=0; t < CYCLES; t++)
> {
> for(i=0; i<NUMBER;i++)
> {
> MyClass[i].run(t);
> }
> }
>
> ////////////////////////////////////////////////////////////////
>
> Along the way some objects should die and vanish from my execution. I
> have no way of knowing which ones and I do not care. The output of my
> program is an ascii file to be processed with other programs. I just
> need to make sure that the objects which are supposed to die actually
> die and that all memory associated to them is released, without
> altering the order in which the other objects are stored. I do not
> need a list. I am using and really need a vector.

Maybe I didn't quite get your problem, but how can you possibly want to
have memory released within a vector? Vectors are stored in a contiguous
area of memory, so you cannot release parts of it. You may want to use
pointers, if NUMBER is not too big and you can afford dereferencing, or
renounce to release the memory of the dead objects and mark them somehow
as dead calling their destructor at the end (or modifications of this
idea according to your needs).

Best wishes,

Zeppe