推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
linxy19957
V2EX  ›  Python

ctypes 库里的 create_string_buffer 缓冲区能被截断吗?

  •  
  •   linxy19957 · Nov 6, 2017 via Android · 4041 views
    This topic created in 3244 days ago, the information mentioned may be changed or developed.
    问题是这样的,我调用 create_string_buffer 创建了一个 100mb 大小的缓冲区,然后调用了某个 dll 的函数修改了这个 buffer,dll 给我返回了修改的长度。
    我想调用 socket 的 sendall 函数把被修改的那部分发送出去,sendall(buf[:len])可以满足我的需求,但是 python 内部似乎是另外创建了一个字符串对象然后进行了拷贝,在数据量大的时候 cpu 占用有点高。
    请问有没有办法能对 buffer 进行一个截断,在实际不影响 buffer 大小的情况下,让 sendall 函数只发送部分数据呢?
    2 replies  •  2017-11-06 23:19:26 +08:00
    justou
        1
    justou  
       Nov 6, 2017
    试试 memoryview
    NoAnyLove
        2
    NoAnyLove  
       Nov 6, 2017
    Python 中使用 slice 都会创建一个新的拷贝,memory slice 不会创建底层映射的拷贝
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   890 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 19:36 · PVG 03:36 · LAX 12:36 · JFK 15:36
    ♥ Do have faith in what you're doing.