Memory Management And Smart Pointer In C++ Programming

Memory Management

Bigelow et al. (2015) opined that memory management is one of the big issues in fundamental programming. Though, it’s an important aspect to manage memory in the programming environment using C++ [1].  Lakhotia, Harman and Gross (2013) stated that smart pointers are the class objects which look as well as feel like pointer, but they are smarter [2].

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

 This report is designed to explain the use of C++ language in memory management and smart pointer in programming environment.

1. Memory Management

Consider we have numerous procedures for which we have to assign memory, if we designate memory for one process and move to second process for portion, so in what manner will you monitor last distributed memory obstruct, for this we have to store some metadata with dispensed memory square, for example, pointer focuses to a next square, memory address, is free and so on [3].

Memory administration is most likely the most concerning issue when utilising C++. Memory administration mistakes are both simple to make and hard to recognise. C++ infers three implicit memory administration issues – 

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
  • C++ does not check cluster limits. Consequently, issues happen when insufficient memory is designated.
  • Another issue includes pointer administration and emerges when pointers speak to objects. The ill-advised utilisation of pointers brings about dangling references, which happen when memory is dispensed and afterwards de-assigned, yet the pointer is still being used.
  • Also, it is conceivable to allow memory and never de-dispense it, even after all pointers to it have been pulverised. This outcomes in memory spill.

In C++ we perceive three sorts of memory administration – programmed, static assignment and dynamic portion –

  • Automatic management: It is confined to managing neighbourhood factors. It is also known as Stack Allocation. For this situation, the memory dispensed for a nearby consideration is de-designated consequently toward the finish of the variable’s extension [4]. Henceforth, it is risky to utilise pointers with adjacent factors, since this is a potential dangling reference case.
  • Static Allocation: It is utilised for putting away common factors and factors pronounced static (both neighbourhood static factors and immobile class individuals). Those factors need to persevere for the whole keep running of the program [5]. In static allotment, a specific scope of memory is put aside for the capacity of static factors, and this memory can never be utilised for whatever else for the span of the program.
  • Dynamic allocation: It is asked for by utilising the new and erase catchphrases. Generally speaking, C++ does not naturally de-apportion anything assigned with new, i.e. to free progressively distributed articles we should employ the erase watchword. We should refer to here that new and delete conceivably costly tasks, “on account of the additional accounting the memory director must do, and regularly because of the additional accounting the software engineer must do” [7]. Furthermore, C++ executes a capacity malloc() that like new powerfully designates memory. The malloc() work restores a pointer of sort void to a memory cradle of the asked for memory square.

2. Smart Pointer

Utilising smart pointers, we can make pointers to work in way that we don’t have to call erase unequivocally. Shrewd pointer is a wrapper class over a pointer with administrator like * and – > over-burden. The objects of keen pointer class look like pointer, however, can do numerous things that a typical pointer cannot care for programmed decimation (truly, we don’t need to utilise erase expressly), reference checking and that’s just the beginning [14].

The thought is to make a class with a pointer, destructor and over-burden administrators like * and – >. Since destructor is naturally considered when a protest leaves scope, the progressively apportioned memory would consequently be erased (or reference tally can be decremented). Consider the accompanying basic smartPtr class. Smart pointers are likewise valuable in the administration of assets, for example, document handles or system attachments. C++ libraries give executions of savvy pointers as auto_ptr, unique_ptr, shared_ptr and weak_ptr [6].

Smart pointer is utilised to make more effective utilisation of accessible memory and to abbreviate distribution and deallocation time.  A typical methodology for utilising memory all the more proficiently is duplicate on compose (COW) [13]. This implies a similar question is shared by many COW pointers as long as it is just perused and not changed. At the point when some piece of the program endeavours to change the protest (“compose”), the COW pointer makes another duplicate of the question and alters this duplicate rather than the first question [8]. The standard string class is usually actualised utilising COW semantics (see the <string> header).

Smart Pointer

Improved distribution plans are conceivable when you can make a few suspicions about the articles to be allotted or the working condition [9]. For instance, you may realise that every one of the articles will have a similar size, or that they will all live in a single string. Even though it is conceivable to execute improved designation plans utilising class-particular new and erase administrators, brilliant pointers give you the opportunity to pick whether to utilise the upgraded plan for each protest, rather than having the plan set for all objects of a class [10]. It is subsequently conceivable to coordinate the portion plan to various working conditions and applications, without altering the code for the whole class.

The C++ standard library incorporates an arrangement of holders and calculations known as the standard layout library (STL). STL is intended to be conventional (can be utilised with any protest) and proficient (does not acquire time overhead contrasted with options) [11]. To accomplish these two plan objectives, STL holders store their items by esteem. This implies if you have an STL compartment that stores objects of class Base, it can’t store of objects of classes got from Base.

Conclusion

It is noticed that programming of memory management using C++ is more powerful that gives full control over the entire memory management process. However, it is also identified that lack of automatic memory mechanism exposed by C++ may result in the memory leak and dangling pointer.

References

[1]      D. Bigelow, T. Hobson, R. Rudd, W. Streilein, and H. Okhravi, “Timely Rerandomization for Mitigating Memory Disclosures,” in The 22nd ACM SIGSAC Conference on Computer and Communications Security (CCS2015), 2015.

[2] K. Lakhotia, M. Harman, and H. Gross, “AUSTIN: An open source tool for search-based software testing of C programs,” in Information and Software Technology, 2013.

[3]      K. Anand et al., “A compiler-level intermediate representation based binary analysis and rewriting system,” in Proceedings of the 8th ACM European Conference on Computer Systems – EuroSys ’13, 2013.

[4]      S. Nagarakatte and M. Zdancewic, “WatchdogLite: Hardware-Accelerated Compiler-Based Pointer Checking,” Cgo, 2014.

[5] G. J. Duck and R. H. C. Yap, “Heap bounds protection with low-fat pointers,” in CC 2016: Proceedings of the 25th International Conference on Compiler Construction, 2016.

[6]      T. C. Stewart, F.-X. Choo, and C. Eliasmith, “Spaun: A Perception-Cognition-Action Model Using Spiking Neurons,” Proc. 34th Annu. Meet. Cogn. Sci. Soc. CogSci 2012, 2012.

[7]      M. C. Rodriguez-Sanchez and J. Martinez-Romo, “GAWA – Manager for accessibility Wayfinding apps,” Int. J. Inf. Manage., 2017.

[8]      J. Qiu et al., “Going Deeper with Embedded FPGA Platform for Convolutional Neural Network,” in Proceedings of the 2016 ACM/SIGDA International Symposium on Field-Programmable Gate Arrays – FPGA ’16, 2016.

[9]      A. Sivieri, L. Mottola, and G. Cugola, “Building Internet of Things software with ELIoT,” Comput. Commun., 2016.

[10]    Y. Sui, D. Ye, and J. Xue, “Static memory leak detection using full-sparse value-flow analysis,” in Proceedings of the 2012 International Symposium on Software Testing and Analysis – ISSTA 2012, 2012.

[11]    F. Winterstein, S. Bayliss, and G. A. Constantinides, “High-level synthesis of dynamic data structures: A case study using Vivado HLS,” in FPT 2013 – Proceedings of the 2013 International Conference on Field Programmable Technology, 2013.

[12]    F. J. Winterstein, S. R. Bayliss, and G. A. Constantinides, “Separation Logic for High-Level Synthesis,” ACM Trans. Reconfigurable Technol. Syst., 2015.

[13]    G. Weisz, J. Melber, Y. Wang, K. Fleming, E. Nurvitadhi, and J. C. Hoe, “A Study of Pointer-Chasing Performance on Shared-Memory Processor-FPGA Systems,” in Proceedings of the 2016 ACM/SIGDA International Symposium on Field-Programmable Gate Arrays – FPGA ’16, 2016.

[14]    S. Ullrich, Y. C. de Vries, S. Kühn, D. Repantis, M. Dresler, and K. Ohla, “Feeling smart: Effects of caffeine and glucose on cognition, mood and self-judgment,” Physiol. Behav., 2015.

Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
4.9
Sitejabber
4.6
Trustpilot
4.8
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.