Monday, September 01, 2008

Monday Development Log

Monday:
  1. ToString() goals: 1) Implement call signature "sprintf(stdout, "%s\n", a_class.ToString());" 2) Deallocate returned char * within the object implementing ToString()--the caller doesn't have to worry about deallocating the returned char *. 3) Reduce memory bloat and handle arbitrary string lengths. 4) No streams (Google prohibits C++ streams (except for logging)). 5) If possible, avoid declaring extra class member variables.
  2. There ain't no such thing as a free lunch in C++, however. Deallocation occurs two ways--first, when variables declared on the stack go out-of-scope; and second, when variables declared on the heap get freed. The callee, in this case, deallocates the memory. The callee can deallocate the memory in these ways: 1) new within ToString(), delete within the object destructor, 2) statically declare within ToString(), deallocate at end of run-time, and 3) automatically declare within ToString(), deallocate when variable goes out-of-scope. The last choice fails because automatic allocations get reclaimed on the stack immediately when the callee returns. The first choice requires maintenance of a pointer to the new'd memory. The second choice requires a compile-time allocation of memory.
  3. Of the options, the first choice allows unlimited flexibility at the cost of additional overhead, while the second choice eliminates the overhead but requires a compile-time allocation of memory.
  4. Estonian Arvo Pärt's "Spiegel im spiegel", from his album Alina. "Spiegel im spiegel" (from Wikipedia): "can mean both "mirror in the mirror" as well as "mirrors in the mirror", referring to the infinity of images produced by parallel plane mirrors."

No comments:

Blog Archive