Monthly Archives: March 2012

Test Prep and Project reminiscing

This week we resumed where we had left off the weeks before we went on spring break wrapping up our discussion of different c++ array/pointer/vector equivalence notations. I found this discussion to have been rather enlightening but the high point was that vector provides near array performance speeds without the hassle and it provides handy initialization methods too.

After putting the finishing touches on the project I started to prepare my one page for the test, I found that the notation that confused me the most was the notion of pointers to functions as they didn’t follow the general pattern that I had associated with typedefs that being: typedef <type> <alias name>. Going into the test I felt fairly prepared and I hope the hours spent studying pay off. In reflecting on the test I can only say that I expected more diversity and I hope that all tests don’t follow this pattern as one missed class or one omission of a detail could prove cost up to half of the test.

Advertisements

templating vs pointers, array object vs primitive storage, and the glory of STL vectors in C++

This post shall be rather short in its nature as it is already past due and I am still trying to finish up my workload that I had on my “break”. Two weeks ago in OOP we took some time to observe the nuances of array initialization with a high point being demonstrated by quiz 20, namely showing that an array of type A instantiated with Bs would create the invocation pattern: B constructor, A constructor, A copy Constructor, B destructor and lastly when the Array exited the function scope of invocation A destructor would be called.We also looked at templating examples and pointers. The high point there being that templating allowed for more types of iterators than pointers, but that some iterators imposed restrictions on the order in which their functions were called, namely the read iterator, and the * and == operators. We also briefly discussed why the STL was nice, and the fact that vectors are similar but much faster than java ArrayLists. The high points being attempt to use STL or Boost to save some troubles and a reference to the fact that C++ vectors subscript([]) operator did not suffer from the linear time look-up like java’s List interface does, however there is some overhead on the .at operator.

 

Arrays and Pointers galore

This week in OOP, we spent most of our time iterating over the different types of pointers in C++ and motivating some examples, the discussion stems from the fact that there are 4 varients of pointers in c++ which can be summed up by the following code and comments:

int c;

int* b; // read/write, many locations

cont int* pc; // read only, many locations

int* const cp = &c; // read/write one location (same as doing int& cp = c;)

const int* const cpc = &c; // read only, one location

We took some time later on to discuss the fact that in java arrays are allocations of values only if the data members are primitive types and for all non-primitives the array holds references to the type, unlike in c++ where the arrays contain the values themselves and can either be stack allocated or heap allocated, unlike java where all stack values reside on the heap.We finished up the week by looking at pointers vs. arrays in c++ noting that pointers are rvalues where arrays seem to be lvalues.