tisdag 27 december 2011

w1d5: Thought: Weak links

Weak links is a good addition/future work Each memory chunk would have a back pointer to the headers where handles are stored.


struct weak_handle_t;

struct chunk_info_t {
    // ...
    struct weak_handle_t *weak_handle; // linked list
    // ...
};

struct handle_t {
    chunk_info_t *chunk;
};
struct weak_handle_t {
    struct handle_t *handle; // not for inheritance use. NULL when auto-free'd
};

Handy for caches where data should be thrown out as needed.

Inga kommentarer:

Skicka en kommentar