|
From: Raoul G. <rao...@ya...> - 2006-01-27 16:29:52
|
--- Louis Pecora <pe...@an...> wrote:
> Raoul Gough wrote:
> > I have a low-level C++ tracing class that I'm trying to wrap for
> > Python, which has an interface like this:
> >
> > struct TraceObject {
> > TraceObject(char const *functionName);
> > // ...
> > private:
> > char const *m_functionName;
> > };
> >
> > The problem is that it assumes the string passed to the constructor
> has
> > static storage duration, e.g.
[snip]
> >
> I'm sorry, but I must be missing something. Why not create your own
> storage for the input string and copy to that? I assume when the
> calling class is destroyed the trace class will be also, so if you
> write
> the destructor right the memory will only disappear then.
>
> That's all in the C++ end and seems to me it would work. So what am
> I
> missing with the Python end?
Are you suggesting writing a new class in C++ to wrap a TraceObject and
handle duplicating the string and deleting it on destruction? That
would certainly work, but seems more difficult than just saving a
reference somewhere to the original Python string.
On the other hand, if you're suggesting that the TraceObject class
should handle copying and deleting the string itself, that would also
work. Unfortunately, that would have some impact on (a lot of) existing
performance-sensitive C++ code, so I'd never get away with it!
I would have thought this would be a fairly common problem. What do
people generally do about Python reference counting if a wrapped C++
object references something in a Python object?
--
Raoul Gough.
___________________________________________________________
NEW Yahoo! Cars - sell your car and browse thousands of new and used cars online! http://uk.cars.yahoo.com/
|