Message142933
| Author |
bgilbert |
| Recipients |
bgilbert |
| Date |
2011年08月24日.21:53:54 |
| SpamBayes Score |
9.57198e-05 |
| Marked as misclassified |
No |
| Message-id |
<1314222835.27.0.518600149254.issue12836@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Section 15.17.1.15 of the ctypes documentation illustrates the use of cast() thusly:
>>> a = (c_byte * 4)()
>>> cast(a, POINTER(c_int))
<ctypes.LP_c_long object at ...>
>>>
Executing the cast() causes a._objects to gain a reference back to a:
>>> a = (c_byte * 4)()
>>> a._objects
>>> cast(a, POINTER(c_int))
<__main__.LP_c_int object at 0x7fb879065b90>
>>> a._objects
{140430281170384: <__main__.c_byte_Array_4 object at 0x7fb879065dd0>}
>>> a
<__main__.c_byte_Array_4 object at 0x7fb879065dd0>
>>>
If large temporary arrays are allocated, cast, used, and discarded in a tight inner loop, a lot of memory can thus be consumed by self-referencing objects before the garbage collector has a chance to run. Even if this behavior is correct from the perspective of ctypes, it is surprising. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2011年08月24日 21:53:55 | bgilbert | set | recipients:
+ bgilbert |
| 2011年08月24日 21:53:55 | bgilbert | set | messageid: <1314222835.27.0.518600149254.issue12836@psf.upfronthosting.co.za> |
| 2011年08月24日 21:53:54 | bgilbert | link | issue12836 messages |
| 2011年08月24日 21:53:54 | bgilbert | create |
|