[bind10-dev] some tips in using boost::offset_ptr
JINMEI Tatuya / 神明達哉
jinmei at isc.org
Wed Jun 27 07:34:43 UTC 2012
While playing with the prototype version of the scalable in-memory
design, I noticed "naive" (but intuitive) use of boost::offset_ptr
could affect performance pretty severely.
In the beginning I used this form of code a lot:
typedef offset_ptr<SomeStructure> SomeStructurePtr
for (SomeStructurePtr some = some_head; some; some = some->next) {
// do something with "some"
}
The nice thing of this is it's quite compatible with the code using
normal pointers. But in "some = some->next", we need to create a new
offset pointer object and calculate the new offset. In performance
sensitive operation this can be significant. (I've lost specific
numbers, but in my vague memory it could be 30-40% difference in
overall response performance).
So, while it's less intuitive, we need to do something like this in
performance sensitive code:
for (SomeStructure* some = some_head.get();
some != NULL;
some = some->next.get())
Or we can define "getNext()" method for SomeStructure to make it less
ugly:
for (SomeStructure* some = some_head.get();
some != NULL;
some = some->getNext())
---
JINMEI, Tatuya
More information about the bind10-dev
mailing list