ctypes in python size with the `sys.getsizeof(Var)` method vs `ctypes.sizeof(Var)`

前端 未结 3 1236
后悔当初
后悔当初 2020-12-20 23:01

I have a question about variable size in python, I\'m using the the Ctypes because i want a 1 byte number, but when I tried to check it\'s size in python (via sys.gets

3条回答
  •  伪装坚强ぢ
    2020-12-20 23:13

    The ctypes module is used for creating and manipulating C data types in Python. That is why ctypes.sizeof(ctypes.c_byte(1)) returns 1.

    >>> import sys
    >>> help(sys.getsizeof) Help on built-in function getsizeof in module sys:
    
    getsizeof(...)
        getsizeof(object, default) -> int
    
        Return the size of object in bytes.
    

    while

    >>> import ctypes
    >>> help(ctypes.sizeof)
    Help on built-in function sizeof in module _ctypes:
    
    sizeof(...)
        sizeof(C type) -> integer
        sizeof(C instance) -> integer
        Return the size in bytes of a C instance
    
    >>>
    

提交回复
热议问题