Destrying and object without calling a destructor

  • Thread starter Bruno.DiStefano
  • Start date
B

Bruno.DiStefano

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.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
 
E

Erik Wikström


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.
 
Z

Zeppe

Bruno.DiStefano said:
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.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
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top