January 2019
Intermediate to advanced
512 pages
14h 5m
English
To understand local buffer optimization, you have to remember that memory allocations do not happen in isolation. Usually, if a small amount of memory is needed, the allocated memory is used as a part of some data structure. For example, let's consider a very simple character string:
class simple_string { public: simple_string() : s_() {} explicit simple_string(const char* s) : s_(strdup(s)) {} simple_string(const simple_string& s) : s_(strdup(s.s_)) {} simple_string& operator=(const char* s) { free(s_); s_ = strdup(s); return *this; } simple_string& operator=(const simple_string& s) { free(s_); s_ = strdup(s.s_); return *this; } bool operator==(const simple_string& rhs) const { return strcmp(s_, rhs.s_) == 0; } ~simple_string() ...