SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 29 Nov 2017 My Price 10.00

C++ applications that can cause performance problems

I need help with this week's homework. I have attached the word doc containing the assignment.

Week 5 Homework—Memory Leaks

 

Memory leaks are bugs in C++ applications that can cause performance problems with your application or even causing it to crash. A memory leak is the result of failing to deallocate memory that was previously allocated. In C++ the commands

#define _CRTDBG_MAP_ALLOC

#include <stdlib.h>

#include <crtdbg.h>

will enable the debug heap functions. After enabling the debug heap functions, place a call to _crtDumpMemoryLeaks() before an application exit point.

Given the following code, run this code in debug mode. The memory leak report will appear in the Output Window with the debug option. It should look something like this.

 

The output will look like the following.

 

Detected memory leaks!

Dumping objects ->

{142} normal block at 0x0079A948, 25 bytes long.

 Data: <> CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD

{141} normal block at 0x0079A8F8, 20 bytes long.

 Data: <Sheldon         > 53 68 65 6C 64 6F 6E 00 CD CD CD CD CD CD CD CD

Object dump complete.

The information displayed is: the memory allocation number (142), block type (normal), the hexadecimal memory location (0x0079A948), and the size of the block (25 bytes long).

Rewrite the code to remove the memory leaks, and submit the completed code with a screenshot of the output window with no memory leaks detected.

 

#define_CRTDBG_MAP_ALLOC

#include<stdlib.h>

#include<crtdbg.h>

#include<string>

 

 

void memLeak()

{

              int *p = newint;

       char * string1 = newchar[20];

       char * string2 = newchar[25];

       strcpy(string1, "Sheldon");

      

       string2=string1;

       delete p;

}

 

int main(intargc, char* argv[])

{

    memLeak();

       _CrtDumpMemoryLeaks();

      

       return 0;    

}

 

 

C++ code with no memory leaks:

 

 

Screenshot:

Attachments:

Answers

(5)
Status NEW Posted 29 Nov 2017 01:11 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)