The sound of premature optimization

Published August 04, 2004
Advertisement
Played some with smart pointers today. Specifically, mucking around with the guts of boost::shared_ptr. One of the interesting implementation details of boost::shared_ptr is that it can accept a deleter object as a parameter when constructing a shared_ptr. This gives shared_ptr quite a bit of flexibility. The implementation of boost::shared_ptr goes like:

shared_ptr contains two members: a pointer to the object and reference counter object. The reference counter object contains a pointer to a the shared count implementation. The implementation object is polymorphic object contains as members, another copy of the pointer to the object, a copy of the deleter object, and two counters, one for shared_ptr references and one for weak_ptr references. And, as a polymorhpic object, it also has the vtable pointer.

My current experiment differs from shared_ptr by having the shared count object be non-polymorphic. Instead of containing a copy of the deleter object, it contains a pointer to a statically allocated polymorphic object that contains a deleter object. So with the loss of some flexiblity (being able to have deleter objects with state), the size of the object allocated on the heap drops by a little. It seems like it goes from 20 bytes to 16 bytes when I tried it out. While 4 bytes isn't that big a deal, it does drop it down to a power of two, which makes it suitable for use with a binary buddy suballocator.
Next Entry Finally
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

New bug to me

1690 views

Week/Class 9

1524 views

Week/Class 8

1565 views

Week/Class 7

1613 views

The promised files

1843 views

Week/Class 6

1310 views

Week/Session 5

1364 views

Week/Session 4

1306 views

On the soapbox

1406 views

Week/Session 3

1282 views
Advertisement