Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #5718
| From | Ruben Safir <mrbrklyn@panix.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Interpeting valgrind |
| Date | 2011-05-27 18:08 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <iropbj$fp6$2@reader1.panix.com> (permalink) |
| References | (3 earlier) <cone.1306113809.229005.17178.500@monster.email-scan.com> <irek9g$dno$4@reader1.panix.com> <ireoit$iph$1@hoshi.visyn.net> <irf5kn$at1$1@reader1.panix.com> <a6138f2d-ab8f-412a-ae9e-cf2a82cd553d@dn9g2000vbb.googlegroups.com> |
Michael Doubez <michael.doubez@free.fr> wrote:
> On 24 mai, 04:37, Ruben Safir <ru...@mrbrklyn.com> wrote:
>> On Tue, 24 May 2011 00:54:17 +0200, Kai-Uwe Bux wrote:
>> > Ruben Safir wrote:
>>
>> > [...]
>> >> But look at this
>> >> ==26349== 121,600 (1,600 direct, 120,000 indirect) bytes in 100 blocks
>> >> are definitely lost in loss record 17 of 17 ==26349== at 0x4027400:
>> >> operator new(unsigned int) (in
>> >> /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==26349== by
>> >> 0x8048E49: creating_int_list() (test_del2.cpp:105) ==26349== by
>> >> 0x8048A89: main (test_del2.cpp:55) ==26349==
>>
>> >> Ok those lines are as follows - the call function designed to allocate
>> >> a list of integers and return them (in this case to main
>> >> std::cout << "CREATING LIST for ARRAY
>> >> -------------------------------\n"; a[i] = creating_int_list();
>>
>> >> chainlist::List<int> * creating_int_list(){
>> >> // chainlist::List<int> set = new chainlist::List<int>;
>> >> chainlist::List<int> * set = new chainlist::List<int>; int ran;
>> >> for(int i = 0; i < 100; ++i){
>> >> ran=rand();
>> >> set->insert(ran % 100);
>> >> }
>> >> set->display();
>> >> return set;
>> >> }
>>
>> >> If I chose to delete the returned List pointed to by set, it have to be
>> >> done OUT of that function otherwise the function has no point
>>
>> >> So upon complaint i did just that
>>
>> >> for( i=0; i < 100; ++i){
>> >> delete a[i];
>> >> }
>> >> return EXIT_SUCCESS;
>>
>> >> That had NO IMPACT on the report.
>> > [...]
>>
>> > Then, it looks as though the destructor of chainlist::List<int> is not
>> > releasing the resources properly. I looked upthread for that destructor.
>> > It relies upon a method remove_front() which you posted as:
>>
>> > template<class T>
>> > void List<T>::remove_front(){
>> > //// std::cout << "Removing the Front " << front() << " End of List
>> > is "<< endd() << std::endl;
>>
>> > if(front() == 0){
>> > // std::cout << "Front is NULL " << front() << std::endl;
>> > return;
>> > }
>> > if(front() == endd()){
>> > //
>> > // std::cout << "Front is End " << front() << std::endl;
>> > Node<T> * tmp = front();
>> > delete tmp;
>> > front(0);
>> > endd(0);
>> > cursor() = 0;
>> > sizedown();
>> > return;
>> > }
>>
>> > The code looks incomplete, so I cannot comment on the correctness. But
>> > that is, where I would search.
>>
>>
>> I've followed that code very closely and did a shake out of it a month
>> ago when I had a double delete. It definitely walks through the entire
>> list and does the deletions, and the nodes have their own destructors.
>>
>> The pointers themselves can't be deleted and are automatic variable
>
> Well, there are many problem with your code. One is between main() and
> creating_int_list() and the other is that you didn't define a copy
> operator (and copy constructor) for your list.
>
I don't want a copy constructor in the list and there is no need for
one. I don't want a 100meg list being copied around. I want it to
remain in global space on the heap, to be only accessed by references
and pointers (although I'm aware that elide optimization would probably
prevent deep copies anyway).
> int main ( int argc, char *argv[] )
> {
> chainlist::Node<std::string> * string_node;
> chainlist::List<int> myintlist;
> // ...
> myintlist = creating_int_list();
> // ...
> }
>
> chainlist::List<int>& creating_int_list(){
> chainlist::List<int> * set = new chainlist::List<int>;
> srand(12345);
> int ran;
> for(int i = 0; i < 5000; ++i){
> ran=rand();
> set->insert(ran % 101);
> }
> return *set;
> }
>
> I assume you used new here in order to avoid the double delete you
> mentioned.
No - I did that in order to be able to move the pointer of the list out
of the function and keep the list available in the gobal scope. You
can't pass out the local List<> unless it is on the heap.
>
> --
> Michael
>
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar
Interpeting valgrind Ruben Safir <ruben@mrbrklyn.com> - 2011-05-22 23:03 +0000
Re: Interpeting valgrind Sam <sam@email-scan.com> - 2011-05-22 18:36 -0500
Re: Interpeting valgrind mrbrklyn <ceo.brooklyn@gmail.com> - 2011-05-22 17:23 -0700
Re: Interpeting valgrind Sam <sam@email-scan.com> - 2011-05-22 20:23 -0500
Re: Interpeting valgrind Ruben Safir <ruben@mrbrklyn.com> - 2011-05-23 21:41 +0000
Re: Interpeting valgrind Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-05-24 00:54 +0200
Re: Interpeting valgrind Ruben Safir <ruben@mrbrklyn.com> - 2011-05-24 02:37 +0000
Re: Interpeting valgrind Michael Doubez <michael.doubez@free.fr> - 2011-05-24 01:36 -0700
Re: Interpeting valgrind Ruben Safir <mrbrklyn@panix.com> - 2011-05-27 18:08 +0000
Re: Interpeting valgrind Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-05-27 22:43 +0000
Re: Interpeting valgrind Ruben Safir <ruben@mrbrklyn.com> - 2011-05-27 23:01 +0000
Re: Interpeting valgrind Michael Doubez <michael.doubez@free.fr> - 2011-05-29 12:41 -0700
Re: Interpeting valgrind Ruben Safir <ruben@mrbrklyn.com> - 2011-05-24 02:48 +0000
csiph-web