This is about something that standard CS curriculums rarely teach. We always think of data structures as synonyms to containers. We "insert" something, we "delete", or we traverse that "bag" of objects. Then at some point, we figure out that for certain big enough elements, copying data to the container costs more than the actual operations on the container. Later, we go even more crazy and try the discouraged: inserting pointers to the container instead of the actual objects. This leaves us with terrible memory management and long hours of debugging.
An alternative is to think of "intrusive" data structures. As the simplest example, think about a linked list. Instead of inserting the object to a bigger ListNode object like this:
template <typename Obj>
struct ListNode
{
Obj object;
ListNode * next;
}
We can embed the next pointer inside each object inside the list.
struct Object
{
Object * next;
...
}
Read on... for more information: http://www.codefarms.com/publications/intrusiv/Intrusive.pdf
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment