making STL use " __malloc_alloc_template<0> "

J

jithoosin

Hi

I am using STL in my code. So after some time it appears as if the
code is leaking memory. I did a memory profiling using valgrind massif
to find out that most memory in my code is allocated using the 2
functions

1) std::__default_alloc_template<true, 0>::allocate(unsigned) (in
/usr/lib/libstdc++.so.5.0.3)
2) std::__default_alloc_template<true, 0>::_S_chunk_alloc(unsigned,
int&) (in /usr/lib/libstdc++.so.5.0.3)

When i googled i found a useful reference:
http://www-1.ibm.com/support/docview.wss?rs=994&context=SSSHAD&dc=DB5...

It asks me to use __malloc_alloc_template<0> in my code so that STL
"actualy frees" memory. So I have 3 questions .
1) Would this strategy be helpful ?
2) Is there any easy way to make my code use this template by any
options rather than changing the code as the link suggests ?
3) How this allocator can be used with a map ?

Thanks in advance.

Regards
Kiran Pradeep
 
J

joosteto

jithoosin said:
Hi

I am using STL in my code. So after some time it appears as if the
code is leaking memory. I did a memory profiling using valgrind massif
to find out that most memory in my code is allocated using the 2
functions

1) std::__default_alloc_template<true, 0>::allocate(unsigned) (in
/usr/lib/libstdc++.so.5.0.3)
2) std::__default_alloc_template<true, 0>::_S_chunk_alloc(unsigned,
int&) (in /usr/lib/libstdc++.so.5.0.3)

When i googled i found a useful reference:
http://www-1.ibm.com/support/docvie...20&uid=swg21160634&loc=en_US&cs=UTF-8&lang=en
It asks me to use __malloc_alloc_template<0> in my code so that STL
"actualy frees" memory. So I have 3 questions .
1) Would this strategy be helpful ?

The page you link to doesn't "ask you to use __malloc_alloc_template",
it merely states that if you do it, then your program will start to
call the free() function. But it also explains that there is really no
point in doing so, as there is no memory leak -- just that at
destruction of the object, the memory is put on the 'cache ready for
re-use' without a call to free().
So if your program is really leaking memory, it isn't because of this.
(valgrind may be complaining because of it, but it isn't an actual
memory leak)
3) How this allocator can be used with a map ?

I just tried to compile the example code provided by IBM, but even the
vector example didn't compile for me. They are probably describing a
different gcc version (I just tried with 3.4.4).

Anyway, I suppose the question is 'off topic' officially, as it's got
more to do with the actual implementation of how g++ allocates/frees
memory than with any C++ standard.

Your actual problem on the other hand may well be on-topic here (the
memory leak itself).

Thanks.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top