|
Boost : |
From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2003-01-15 09:36:20
"Peter Dimov" <pdimov_at_[hidden]> wrote in message
news:00bc01c2bc89$d77fe5e0$1d00a8c0_at_pdimov2...
> From: "Philippe A. Bouchard" <philippeb_at_[hidden]>
> > 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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk