This week we went over important concepts such as specialized templates, stacks vs heap allocations, and function pointers.
Specialized templates provide a way of defining secondary templates that can be useful where a known different (and may more efficient) algorithm is to be used to perform a particular task with a particular data type(s). From compiler's perspective, the way function calls are determined is by following order:
(i) Check if there is a non-template version available for the function call. If one does exist call that.
(ii) If the function call is a templatized version, determine the primary template structure.
(iii) Once the primary template structure is determined, check if there is a secondary template version (a specialized function with the matching signature) is available. If a secondary template is available, call that function, else call the primary templatized function.
During the week, we studied how stack allocated arrays differ from heap allocated ones, and in what ways they are similar. Heap allocation offers the flexibility of allocating memory spaces as per the need, but at the same time the programmer is responsible for tracking the allocated memory, and freeing them appropriately when need be so. A rule of thumb is to have as many delete's as there are new's (with appropriate placements). This ensures that there are no memory leakage. A few conceivable problems with heap allocated arrays can be: not freeing memory after use, deleting the wrong memory address, deleting more than needed.
Next, we started on function pointers which in a sense provides a way of customized function calls. The function pointers, allows function calls via pointers that like any other pointer can be changed to call other function.
This week, and the following week I along with my partner will be working on the Project 4 - Integer. The project involves creating a class that implements Big Integer/Arbitrary Precision operations. The idea is to represent numbers with vector/deque where each element is an individual digit, and perform operations on these digits.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment