Difference: CSC458Spring2008 (21 vs. 22)

Revision 222008-02-08 - LukeDalessandro

Line: 1 to 1
 
META TOPICPARENT name="TongxinBai"
This class wiki serves as both a blackboard for technical discussions and a billboard for information sharing. The organization of this wiki is made as simple as possible but hopefully also effective enough for discussion and Q&A. In general, postings go to one of the four sections below. The Announcements is basically used for reminding students of the class schedule and homework due dates. The on Administration is where you put questions about class administration, for instance, about grading criteria. The other two sections are the places for technical discussions. All the specific questions and issues about the assignments go to on Assignments. The other general questions and comments about the course content go to on Technical Content.
Line: 62 to 62
  -- LukeDalessandro - 07 Feb 2008
Added:
>
>
A note on unions. The easiest way to implement a counted pointer is with a union. You wind up with something like (in C++):

union counted_ptr {
    unsigned long long ull_for_casx_or_mvx;
    struct {
        Node* ptr;
        unsigned long count;
    };
};

or, for a templated version:

template <typename T>
struct counted_ptr {
    union {
        unsigned long long ull_for_casx_or_mvx;
        struct {
            T* ptr;
            unsigned long count;
        };
    };
};

So if you have counted_ptr<Node> head; you can say if (head.ptr == NULL) and you can also say casX(&head.ull_for_casx_or_mvx, ...). This avoids explicit casting and makes code easier to figure out. If you're using C++ you can also give the union or struct members like T* operator->() or nice constructors to make it easier and safer to use.

As a side note, you should be able to template the union version directly, but I can't seem to get g++ to like it when I do. Hope this helps someone.

-- LukeDalessandro - 08 Feb 2008

 

on Technical Content

\ No newline at end of file
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding URCS? Send feedback