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
Sherlockhlt
V2EX  ›  Python

Python3的long实现问题

  •  
  •   Sherlockhlt · 2013-03-27 17:10:21 +08:00 · 4807 次点击
    这是一个创建于 4054 天前的主题,其中的信息可能已经有所发展或是发生改变。
    两个问题,困惑了我好久:
    1. Python3中是不是把int都改成long,然后对外申称都是int了?
    2. Python3中是不是long都改成不缓存了?在longobject.c里面没有看到对象缓存(free list)的代码。
    4 条回复    1970-01-01 08:00:00 +08:00
    timonwong
        1
    timonwong  
       2013-03-27 17:22:14 +08:00
    1. 嗯,统一为int,就是Python 2.x的long
    2. 有的:
    int
    _PyLong_Init(void)
    {
    #if NSMALLNEGINTS + NSMALLPOSINTS > 0 // 从这里开始分配
    ...... 一段代码
    #endif // 这里结束
    /* initialize int_info */
    Sherlockhlt
        2
    Sherlockhlt  
    OP
       2013-03-27 19:30:53 +08:00
    @timonwong
    这一段是存放小整数的,只存放[-5,257)
    在2.6.x中,大整数是用自由链表来缓存的,但是在3.0找了很久都找不到。。
    timonwong
        3
    timonwong  
       2013-03-27 20:59:54 +08:00
    @Sherlockhlt
    刚才理解错了,确实没有freelist了
    这里有相关的issue
    http://bugs.python.org/issue2013
    Sherlockhlt
        4
    Sherlockhlt  
    OP
       2013-03-27 21:46:18 +08:00
    @timonwong
    哦,原来他们觉得优化不够明显就删掉了。。3.0改动真多阿
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   798 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:03 · PVG 06:03 · LAX 15:03 · JFK 18:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.