来自正则表达式的matchobj是否分配了单独的内存? 我看到它被分配了不同的内存地址(id()是字符串测试的差异)
test=....
>>> import re
>>> matchobj=re.match(r'(.*) key=({.*}) .*', test)
>>> matchobj.group(2)
'{xxxx#####xxxx}'
>>> type(matchobj)
<type '_sre.SRE_Match'>
>>> id(matchobj)
4344654000
>>> id(test)
4343948752
>>>
>>> id(matchobj.group(2))
4344883632
>>> type(matchobj.group(2))
<type 'str'>
但是我无法使用ctypes.memset清除matchobj.group(2)中的数据。
>>> import sys
>>> import ctypes
>>> size=sys.getsizeof(matchobj.group(2))
>>> buf=len(matchobj.group(2))+1
>>> offset=size - buf
>>> ctypes.memset(id(matchobj.group(2)) + offset, 0, buf)
4344884756
>>> offset
36
>>> matchobj.group(2)
'{xxxx#####xxxx}'
>>>
为什么我们无法清除分配给matchobj.group(2)的内存,如果它只是一个字符串?