V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
wave4yy
V2EX  ›  Python

想请教一下, python2 和 3 在 ctype 上的差异

  •  
  •   wave4yy · 2019-10-22 19:31:06 +08:00 · 2127 次点击
    这是一个创建于 1619 天前的主题,其中的信息可能已经有所发展或是发生改变。
    初学 ctypes,试了一段代码
    from ctypes import *
    import win32con

    k32 = windll.kernel32

    size = 20
    sa = k32.LocalAlloc(win32con.LMEM_FIXED, size)
    if sa == 0:
    print("Memory Alloc Failed")
    else:
    print("sa: {}".format(hex(sa)))

    发现这段代码在 python2 中申请的地址都是 c_int32 型,而在 python3 申请的内存地址都是 c_int64 型,有时候还会有 ffff 开头的地址

    python2 版本为 Python 2.7.16 [MSC v.1500 64 bit (AMD64)] on win32
    python3 版本为 Python 3.7.5 [MSC v.1916 64 bit (AMD64)] on win32

    想问一下这是由什么原因导致的,有没有什么解决办法?
    2 条回复    2019-10-23 12:15:20 +08:00
    imiao
        1
    imiao  
       2019-10-22 20:28:42 +08:00 via Android
    你装的 python2 和 3 都是 64 位的吗?
    wave4yy
        2
    wave4yy  
    OP
       2019-10-23 12:15:20 +08:00
    @imiao 是的

    python2 版本为 Python 2.7.16 [MSC v.1500 64 bit (AMD64)] on win32
    python3 版本为 Python 3.7.5 [MSC v.1916 64 bit (AMD64)] on win32
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5273 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:26 · PVG 09:26 · LAX 18:26 · JFK 21:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.