Usually in Python when you do an assignment of a variable, you don't get a copy - you just get a second reference to the same object.
a = b'Hi'
b = a
a is b # shows True
Now when you use ctypes.create_string_buffer
to get a buffer to e.g. interact with a Windows API function, you can use the .raw
attribute to access the bytes. But what if you want to access those bytes after you've deleted the buffer?
c = ctypes.create_string_buffer(b'Hi')
d = c.raw
e = c.raw
d is e # shows False?
d == e # shows True as you'd expect
c.raw is c.raw # shows False!
del c
At this point are d
and e
still safe to use? From my experimentation it looks like the .raw
attribute makes copies when you access it, but I can't find anything in the official documentation to support that.