Destrying and object without calling a destructor

  • Follow


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


0
Reply Bruno.DiStefano (24) 9/3/2008 3:48:26 PM

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
0
Reply Erik-wikstrom (1881) 9/3/2008 4:33:09 PM


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
0
Reply zep_p1 (104) 9/3/2008 5:39:35 PM

2 Replies
32 Views

(page loaded in 0.074 seconds)


Reply: