"Peter Dimov" <[EMAIL PROTECTED]> wrote in message
00bc01c2bc89$d77fe5e0$1d00a8c0@pdimov2">news:00bc01c2bc89$d77fe5e0$1d00a8c0@pdimov2...
> From: "Philippe A. Bouchard" <[EMAIL PROTECTED]>
> > Greeting everyone,
> >
> >     It seems placement operator new (size_t, ...) would extend a lot
> garbage
> > collection possibilities.  Why don't we define a set of rules for each
tag
> > this overloaded placed operator would use:
> >
> > shared_ptr<int>(new int());
> >
> > GC type defined at run-time:
> > shared_ptr<int>(new (gc) int());  // Add pointer to a list
> > shared_ptr<int>(new (rc) int());  // Add counter + pointer to a list
> > shared_ptr<int>(new (os) int());  // Add owner to a list
>
> I am not sure how these are intended to work, and in particular, how is
> shared_ptr<> supposed to handle the different variations, given that it
gets
> a plain "int *" in all cases.

- ownership is similar to weak_ptr.
- agreeing with M. Colvin on operator new (size_t, gc) thought.


Define only 2 allocators then:

// Standard allocator version
void * operator new (size_t);

// GC allocator version
void * operator new (size_t s, gc const &)
{
    // Simple list version
    static list<void *> garbage_collection;

    // Pointers with stack depth version
    static map<int, void *> garbage_collection;

    // Add memory swapping
    static ...;
    static list< pair<void *, void *> > swapped_memory;

    void * p = malloc(s);

    if (p)
    {
        // Add pointer to the appropriate list
        garbage_collection.push_back(p);
        ...;
    }
    else
    {
        // Swap memory if needed
        ...;
    }

    return p;
}


    I've examined other possibilities but I think this one is more
interesting... other one mostly helped to warm up.  operator new (size_t,
rc/os) would require yet another distinct smart pointer.



Philippe A. Bouchard




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to