2
我有一個TCP客戶端服務器通信。我正在發送字符串,我想測量包的大小,我該怎麼做?如何獲取字符串的大小?
在我的情況下sys.getsizeof並不好,因爲
getsizeof() calls the object’s __sizeof__ method and adds an additional garbage collector
overhead if the object is managed by the garbage collector.
什麼是一個字符,2個或4個字節的大小?在這種情況下,我可以簡單地測量爲msg_size = x * len(msg)
,但我不知道有多少字節是x
len(string)返回字符串使用的字節數(len(ustring)返回字符數) – njzk2