msg71495 - (view) |
Author: Roger Upole (rupole) |
Date: 2008-08-19 22:50 |
When using PyMemoryView_FromMemory to create a new object, you have to pass in a preallocated buffer. However, there's no way to specify a routine to free the memory, and it leaks when the object is destroyed. |
|
|
msg71496 - (view) |
Author: Benjamin Peterson (benjamin.peterson) *  |
Date: 2008-08-19 22:54 |
PyMemoryView_FromMemory doesn't exist. Do you mean PyMemoryView_FromBuffer or PyMemoryView_FromObject? |
|
|
msg71498 - (view) |
Author: Roger Upole (rupole) |
Date: 2008-08-19 23:03 |
Well it existed up until a couple hours ago ;). Looks like it was recently changed to PyMemoryView_FromBuffer. However, it still has the same issue. |
|
|
msg71526 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2008-08-20 09:43 |
Well, this is not a bug in itself. Memoryview objects are designed to give access to a memory area backed by another object - they don't "own" the memory by themselves (in the sense that you e.g. own a reference to a PyObject). Please note by the way that the Py_buffer struct now has a reference to the original object, the "obj" field. PyBuffer_FillInfo() will incref it, and PyBuffer_Release() will decref it again. However, it you set this field to NULL, you are responsible for doing your own reference management. I agree that it may be nice to support your use case, but I'm not sure what the semantics should be. For clarity, perhaps it should be a derived class of memoryview. |
|
|
msg71562 - (view) |
Author: Roger Upole (rupole) |
Date: 2008-08-20 18:04 |
As background, what I need is an equivalent of PyBuffer_New(size), which creates an object that manages its own buffer memory, and is not based on another object at all. |
|
|
msg71563 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2008-08-20 18:11 |
> As background, what I need is an equivalent of > PyBuffer_New(size), which creates an object that manages its > own buffer memory, and is not based on another object at all. Well, you can create either a bytes or bytearray object with an internal buffer of the desired length. Then you'll be able to create a memoryview out of it. |
|
|
msg71567 - (view) |
Author: Roger Upole (rupole) |
Date: 2008-08-20 18:54 |
Aha, thanks. I'll go that route for now. |
|
|