Skip to Content
Hands-On Design Patterns with C++
book

Hands-On Design Patterns with C++

by Fedor G. Pikus
January 2019
Intermediate to advanced
512 pages
14h 5m
English
Packt Publishing
Content preview from Hands-On Design Patterns with C++

The main idea

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() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Structural Design Patterns in Modern C++

Structural Design Patterns in Modern C++

Umar Lone

Publisher Resources

ISBN: 9781788832564Supplemental Content