Google Groups

Issue 381 in protobuf: Do not use heap where stack can be used


prot...@googlecode.com Apr 3, 2012 8:00 AM
Posted in group: Protocol Buffers
Status: New
Owner: liuj...@google.com
Labels: Type-Defect Priority-Medium

New issue 381 by NN14...@gmail.com: Do not use heap where stack can be  
used
http://code.google.com/p/protobuf/issues/detail?id=381

In generated code you see following lines:

ImportMessageLite::default_instance_ = new ImportMessageLite();
Message1::default_instance_ = new Message1();
Message2::default_instance_ = new Message2();
...

Instead of heap a stack can be used with placement new trick.
Same as boost::optional does  
http://www.boost.org/doc/libs/1_49_0/libs/optional/doc/html/index.html
You can adapt this method and decrease heap fragmentation.