Re: C++ auto_ptr template query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/24/06, John (Eljay) Love-Jensen <eljay@xxxxxxxxx> wrote:
HI Digvijoy,

std::auto_ptr is for holding a single object, not arrays of objects.

Don't use std::auto_ptr to hold arrays of objects.

Use a std::list<Car> instead.
try
{
  std::list<Car> carList;
  carList.push_back(Car());
  carList.push_back(Car());
  carList.push_back(Car());
}

Or I bet Boost (www.boost.org) has something like a std::auto_ptr that holds arrays of objects.

HTH,
--Eljay


Hello Eljay,
I tried using std::list<Car> as you have suggested above, the code as
above runs but tells me :
*** glibc detected *** double free or corruption (fasttop): 0x0804b038 ***
and  i loose 40 bytes, (the last Car when it allocated 10 ints but the
Motor fails )
if I comment the delete M ,and delete []a in the Car destructor
method, there is no double free corruption detected ,
 ~Car ()
{
  //delete []a;
  //delete M1;
}
but when i run valgrind :
==32159== LEAK SUMMARY:
==32159==    definitely lost: 122 bytes in 5 blocks.
which is i think
[(4 * 10 ints) *3 Car objs ]=120
[ (1*1Motor) * 2 Car objs ] =2
Any  suggestions ???
Digz


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux