This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author methane
Recipients Yury.Selivanov, belopolsky, methane, ncoghlan, serhiy.storchaka, vstinner, xiang.zhang, yselivanov
Date 2017-01-07.12:47:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1483793228.76.0.423850300358.issue29178@psf.upfronthosting.co.za>
In-reply-to
Content
> I'm -1 if the intention is about easiness and efficiency. 

Do you +1 when adding it to stdlib (say "bufferlib")?

> Creating a memoryview is not cheap enough in such a case.

Actually speaking, it's 5 calls + 2 temporary memoriview.

1. creating memoryview.
2. call __enter__.
3. slicing memoryview
4. create bytes from it
5. call __exit__

It can be bottleneck very easily, when writing protocol parser like HTTP parser.

> About easiness to use, when a user considering such low level details, it's reasonable to know memoryview and it needs to be released.

closing memoryview is not strict requirements in some cases.
When memoryview is created from immutable, relying to GC is safe.
That's why closing memoryview is easily forgotten.

> But if this API is added to simplify bytes(), I think it makes sense but it's not only about adding a frombuffer().

Yes. See msg284813.
There are PEP 467 already to make bytes() simple.

But if PEP 467 is accepted, bytes() constructor is simple enough.
Adding `offset` and `length` keyword-only argument to bytes() make sense.
History
Date User Action Args
2017-01-07 12:47:08methanesetrecipients: + methane, ncoghlan, belopolsky, vstinner, Yury.Selivanov, serhiy.storchaka, yselivanov, xiang.zhang
2017-01-07 12:47:08methanesetmessageid: <1483793228.76.0.423850300358.issue29178@psf.upfronthosting.co.za>
2017-01-07 12:47:08methanelinkissue29178 messages
2017-01-07 12:47:08methanecreate