C extension - new and init functions

Hrvoje Niksic hniksic at xemacs.org
Mon Nov 17 04:40:21 EST 2008


Paul  Moore <p.f.moore at gmail.com> writes:

> OK, but that allocates the initial buffer, which I will then throw
> away.

Why don't you use a constructor argument that allows specifying the
initial buffer size?

> In practice, this isn't a significant issue (the overhead of one
> allocation and one deallocation isn't going to wreck things!) but it
> feels somehow clumsy. However, I can't see an obvious way to
> refactor the code so that building the object and assigning the
> buffer are separate - so that I can write a function like
> Pattern_init, which allocates a differently sized buffer (well, I
> could, but if I did, I'd have no way of using it that respects
> subclassing...

Another way would be to avoid allocating the buffer at all until it is
actually needed.



More information about the Python-list mailing list