内存分配问题
-
```
import sysbase64_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
f = open('dd.jpg','rb')
def encode(origin_bytes):
base64_bytes = ['{:0>8}'.format(str(bin(b)).replace('0b', '')) for b in origin_bytes]resp = '' nums = len(base64_bytes) // 3 remain = len(base64_bytes) % 3 integral_part = base64_bytes[0:3 * nums] while integral_part: tmp_unit = ''.join(integral_part[0:3]) tmp_unit = [int(tmp_unit[x: x + 6], 2) for x in [0, 6, 12, 18]] resp += ''.join([base64_charset[i] for i in tmp_unit]) integral_part = integral_part[3:] if remain: remain_part = ''.join(base64_bytes[3 * nums:]) + (3 - remain) * '0' * 8 tmp_unit = [int(remain_part[x: x + 6], 2) for x in [0, 6, 12, 18]][:remain + 1] resp += ''.join([base64_charset[i] for i in tmp_unit]) + (3 - remain) * '=' return resp
img = encode(f.read())
-
-
@kidswong999 在 内存分配问题 中说:
https://forum.singtown.com/topic/558/常见问题-memory-error-fb-alloc-collision-内存不够与像素低
那这种问题没法解决吗?
-
不能从硬件上解决。
那就从软件上解决,有时候解决不了,视情况。