[Xapian-tickets] [Xapian] #554: Complement clone() method with destroy()
Xapian
nobody at xapian.org
Wed Jul 27 07:36:38 BST 2011
#554: Complement clone() method with destroy()
-------------------------+--------------------------------------------------
Reporter: olly | Owner: olly
Type: enhancement | Status: new
Priority: normal | Milestone: 1.3.0
Component: Library API | Version:
Severity: normal | Keywords:
Blockedby: | Platform: All
Blocking: |
-------------------------+--------------------------------------------------
Comment(by olly):
Oh, actually the user can implement {{{operator new}}} and {{{operator
delete}}} in their subclass, and that approach doesn't require an extra
virtual method, or the (admittedly small) overhead of calling it for each
object destroyed.
This code demonstrates that this works for the situation we'd have:
{{{
#!cpp
#include <iostream>
using namespace std;
class Base {
int x;
public:
Base(int x_) : x(x_) { }
virtual ~Base() { }
};
class Derived : public Base {
public:
Derived(int x_) : Base(x_) { }
static void* operator new(size_t size) {
cout << "Derived::new(" << size << ")" << endl;
return ::operator new(size);
}
static void operator delete(void * p, size_t size) {
cout << "Derived::delete(" << size << ")" << endl;
::operator delete(p);
}
};
int main() {
Base * o = new Derived(42);
delete o;
}
}}}
This trick probably also opens the way to wrapping {{{Xapian::Weight}}}
(#401).
--
Ticket URL: <http://trac.xapian.org/ticket/554#comment:1>
Xapian <http://xapian.org/>
Xapian
More information about the Xapian-tickets
mailing list