Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
b8d76f57
Commit
b8d76f57
authored
Aug 14, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor doc changes.
parent
1f509bf4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
2 deletions
+35
-2
cxx.md
doc/cxx.md
+35
-2
No files found.
doc/cxx.md
View file @
b8d76f57
...
...
@@ -615,6 +615,40 @@ best reference is the header files. See:
capnp/schema-loader.h
capnp/dynamic.h
## Best Practices
Here are some tips for using the C++ Cap'n Proto runtime most effectively:
*
Accessor methods for primitive (non-pointer) fields are fast and inline. They should be just
as fast as accessing a struct field through a pointer.
*
Accessor methods for pointer fields, on the other hand, are not inline, as they need to validate
the pointer. If you intend to access the same pointer multiple times, it is a good idea to
save the value to a local variable to avoid repeating this work. This is generally not a
problem given C++11's
`auto`
.
Example:
// BAD
frob(foo.getBar().getBaz(),
foo.getBar().getQux(),
foo.getBar().getCorge());
// GOOD
auto bar = foo.getBar();
frob(bar.getBaz(), bar.getQux(), bar.getCorge());
*
If you are worried about the binary footprint of the Cap'n Proto library, consider statically
linking with the
`--gc-sections`
linker flag. This will allow the linker to drop pieces of the
library that you do not actually use. For example, many users do not use the dynamic schema and
reflection APIs, which contribute a large fraction of the Cap'n Proto library's overall
footprint. Keep in mind that if you ever stringify a Cap'n Proto type, the stringification code
depends on the dynamic API; consider only using stringification in debug builds.
If you are dynamically linking against the system's shared copy of
`libcapnp`
, don't worry about
its binary size. Remember that only the code which you actually use will be paged into RAM, and
those pages are shared with other applications on the system.
## Lessons Learned from Protocol Buffers
The author of Cap'n Proto's C++ implementation also wrote (in the past) verison 2 of Google's
...
...
@@ -638,8 +672,7 @@ learned the hard way:
The proliferation of template instantiations gives the Protobuf runtime library a large footprint,
and using STL in the interface can lead to weird ABI problems and slow compiles. Cap'n Proto
does not use any STL containers in its interface and makes sparing use in its implementation.
As a result, the Cap'n Proto runtime library is very small, and code that uses it compiles
quickly.
As a result, the Cap'n Proto runtime library is smaller, and code that uses it compiles quickly.
*
The in-memory representation of messages in Protobuf-C++ involves many heap objects. Each
message (struct) is an object, each non-primitive repeated field allocates an array of pointers
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment