Article View: comp.os.os2.programmer.tools
Article #36VA C++ Memory Debugging
From: Mark Framness
Date: Wed, 28 Jan 1998 00:00
Date: Wed, 28 Jan 1998 00:00
137 lines
5105 bytes
5105 bytes
Greetings
I am working on an exercise (an OOP C++ course) regarding the overloading of
the assignment operator also I'm to define two different + operators (one for
a stack + character and another for
stack + stack).
Now I believe I'm pretty close to getting the assignment done (it seems to
work) and I do not see any place where I'm obviously doing goofy things to
memory, but the longer I work and debug the program the more goofy the system
becomes (one thing was a minimized icon for my e-mail package changed on its
own and things take longer etc). So I figured I might need to look at my
memory use in more detail. I don't see any obvious places where I would have
dangling pointers or am deleting already deleted objects. I'm using copy
constructors as well as the defined assignment operators in order to avoid
such things.
So I enabled the /Tm option on the VA C++ compiler (I'm using the workframe)
and then added the _dump_allocated(10) function at the end of the program.
What I am doing is to allocate two stacks with the below given ctor which will
construct a stack if an integer size is given. Then I push on characters with
the given function. That is all I do here and then when I run the program I
get the below given dump.
Questions:
How do I basically interpret the dump?
How does it relate to the map file generated by the linker?
Do the dumps necessarily indicate an error? I ran a program from Dave
Bricetti's homepage (a little thing designed by him to demonstrate the memory
debugging function of VA C++) and it dumps on an errorless allocation. I
guess I just answered my own question.
How may I redirect the dump to a file?
Thanks for any & all help.
/*********************************/
//Basic functions of the program below.
//I hope the ctor below gives the spirit well enough.
//In my copy ctor I am essentially using the ctor below with the addition of
//a memcpy() function.
//another ctor specifying the size of the stack.
/***************************************************************************/
stack::stack(int big)
{
size=big;
if(!(stck=new char[size]))
{
cout << "Memory allocation error." << endl;
exit(1);
}
tos=0;
}
/***************************************************************************/
// Push a character.
/****************************************************************************/
void stack::push(char ch)
{
if(tos==size)
{
cout <<"Stack is full\n";
return;
}
*(stck+tos)=ch;
++tos;
}
/***************************************************************************/
main()
{
stack s1(3);
stack s2(3);
while(s1.not_full())
{
cout << "Pushing onto s1." << endl;
s1.push('a');
}
while(s2.not_full())
{
cout << "Pushing onto s2." << endl;
s2.push('b');
}
_dump_allocated (10);
return 0;
}
------------------------------------------------------------------------------
-
START OF DUMP OF ALLOCATED MEMORY BLOCKS
------------------------------------------------------------------------------
-
Address: 0x000B39E0 Size: 0x00000003 (3)
This memory block was (re)allocated at line number 146 in
D:\C++\RedWing\MARKF3H
CPP.
Memory contents: 626262 [bbb ]
------------------------------------------------------------------------------
-
Address: 0x000B39A0 Size: 0x00000003 (3)
This memory block was (re)allocated at line number 146 in
D:\C++\RedWing\MARKF3H
CPP.
Memory contents: 616161 [aaa ]
------------------------------------------------------------------------------
-
END OF DUMP OF ALLOCATED MEMORY BLOCKS
------------------------------------------------------------------------------
-
Take Care!
postmaster@[127.0.0.1]
Spam booby trap!!!
FROM: Mark Allen Framness
HOME: framness@.NO_SPAM.EMIRATES.NET.AE
WORK: m477@NO_SPAM.ugru.uaeu.ac.ae
HTTP: http://netnet.net/~farmer/index.html
URL for comp.lang.c NG: http://www.eskimo.com/~scs/C-faq/top.html
To reply via e-mail, delete the given reply to address and delete the NO_SPAM
from the above addresses.
&
All standard disclaimers apply. Anyone who says otherwise is itching for a
fight.
Technical Details
Message-ID:
<6ao9sq$n70@ws1.emirates.net.ae>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1044c2,aaba1dcb5864b861,start X-Google-Attributes: gid1044c2,public X-Google-Thread: 1049cc,aaba1dcb5864b861,start X-Google-Attributes: gid1049cc,public X-Google-Thread: 10cd94,aaba1dcb5864b861,start X-Google-Attributes: gid10cd94,public X-Google-Thread: fecf8,aaba1dcb5864b861,start X-Google-Attributes: gidfecf8,public From: framness@EMIRATES.NET.AE (Mark Framness) Subject: VA C++ Memory Debugging Date: 1998/01/28 Message-ID: <6ao9sq$n70@ws1.emirates.net.ae> X-Deja-AN: 319967316 Distribution: world Organization: PERSONAL Reply-To: framness@EMIRATES.NET.AE Newsgroups: comp.os.os2.programmer.tools,bit.listserv.os2-l,comp.os.os2.misc,comp.os.os2.programmer.oop