做网站都要掌握什么,网站建设中可能升级,学ps做兼职的网站有哪些,营销网站建设的价格python中一般并不需要查看内存内容,但作为从C/C++过来的人,有的时候还是想看看内存,有时是为了验证内容是否与预期一致,有时是为了探究下内存布局。 from sys import getsizeof from ctypes import string_at getsizeof(...) getsizeof(object, default) - int Return… python中一般并不需要查看内存内容,但作为从C/C++过来的人,有的时候还是想看看内存,有时是为了验证内容是否与预期一致,有时是为了探究下内存布局。 from sys import getsizeof from ctypes import string_at ''' getsizeof(...) getsizeof(object, default) - int Return the size of object in bytes. string_at(ptr, size=-1) string_at(addr[, size]) - string Return the string at addr. ''' getsizeof用于获取对象占用的内存大小,string_at用于获取指定地址、指定字节长度的内容,因为返回的对象类型是bytes,可以调用hex()函数转换成16进制查看。 对int对象的内存内容如下,首先通过函数id获取对象的内存地址。 i = 100 type(i) # int s = string_at(id(i), getsizeof(i)) type(s) # bytes s # b'\x00\x00\x00\x00\x00\x00\x00\xa0\x99\xfd\x1d\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00d\x00\x00\x00' s.hex() # '3e00000000000000a099fd1d000000000100000