Skip to content

Instantly share code, notes, and snippets.

@Fraser999
Created May 15, 2013 16:39
Show Gist options
  • Save Fraser999/5585342 to your computer and use it in GitHub Desktop.
Save Fraser999/5585342 to your computer and use it in GitHub Desktop.
Size of boost::optional
#include <iostream>
#include <memory>
#include <string>
#include "boost/optional.hpp"
int main() {
std::unique_ptr<std::string> ptr(new std::string("A"));
boost::optional<std::string> opt_empty;
boost::optional<std::string> opt_full("A");
std::cout << "ptr: " << sizeof(ptr) << '\n';
std::cout << "*ptr: " << sizeof(*ptr) << '\n';
std::cout << "opt_empty: " << sizeof(opt_empty) << '\n';
std::cout << "opt_full: " << sizeof(opt_full) << '\n';
std::cout << "*opt_full: " << sizeof(*opt_full) << '\n';
return 0;
}
@Fraser999
Copy link
Author

MSVC 2012 x64 Release output:

ptr:       8
*ptr:      32
opt_empty: 40
opt_full:  40
*opt_full: 32

MSVC 2012 x64 Debug output:

ptr:       8
*ptr:      40
opt_empty: 48
opt_full:  48
*opt_full: 40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment