Hi
To the best of my knowledge:
std::string is an object.
When created it fetches some memory from the heap like vector, list or
whatever does via the standard allocator - if the allocator has not been
replaced.
So it can store some chars w/o immediately reallocating.
Well,
std::string test;
itself should reside on the stack, thus the administrative data.
However, the payload of string is stored on the heap.
Hope I am right and this helps.
Cheers
Eric
Am 18.11.2011 17:32, schrieb sachin gupta:
Hi All,
I have a simple program
/*************************/
#include <iostream>
#include <string>
main()
{
std::string test;
test ="abc";
std::string *test2 = new std::string("abc");
delete test2;
}
/******************************************/
Now I am running valgrind over it
valgrind --tool=massif ./a.out
on ms_print
it is howing output as
/****************************************
n time(i) total(B) useful-heap(B) extra-heap(B)
stacks(B)
--------------------------------------------------------------------------------
0 0 0 0
0 0
1 1,385,421 40 28
12 0
2 1,388,597 64 36
28 0
3 1,389,777 104 64
40 0
4 1,393,400 104 64
40 0
61.54% (64B) (heap allocation functions) malloc/new/new[],
--alloc-fns, etc.
->53.85% (56B) 0x3D1709B85F: std::string::_Rep::_S_create(unsigned
long, unsigned long, std::allocator<char> const&) (in
/usr/lib64/libstdc++.so.6.0.8)
| ->26.92% (28B) 0x3D1709D10F: std::string::_M_mutate(unsigned long,
unsigned long, unsigned long) (in /usr/lib64/libstdc++.so.6.0.8)
| | ->26.92% (28B) 0x3D1709D28A: std::string::_M_replace_safe(unsigned
long, unsigned long, char const*, unsigned long) (in
/usr/lib64/libstdc++.so.6.0.8)
| | ->26.92% (28B) 0x4009B2: main (test1.c:6)
| |
| ->26.92% (28B) 0x3D1709C363: ??? (in /usr/lib64/libstdc++.so.6.0.8)
| ->26.92% (28B) 0x3D1709C510: std::basic_string<char,
std::char_traits<char>, std::allocator<char> >::basic_string(char
const*, std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.8)
| ->26.92% (28B) 0x4009E3: main (test1.c:8)
|
->07.69% (8B) 0x4009CD: main (test1.c:8)
/*********************
Why valgrind is showing stack variables in heap. Any idea.
Regards
Sachn
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users