logo

内存分配问题

2018-05-24 11:28
Q
_498769
b897d45a-9a9e-4e1d-bfb7-ede7c56d18b6.png

import sys

base64_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())

2018-05-24 11:58
I
网红小智智 星瞳科技

https://forum.singtown.com/topic/558/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98-memory-error-fb-alloc-collision-%E5%86%85%E5%AD%98%E4%B8%8D%E5%A4%9F%E4%B8%8E%E5%83%8F%E7%B4%A0%E4%BD%8E

2018-05-24 14:21
Q
_498769

@kidswong999 在 [内存分配问题](/post/2633) 中说:

>

> https://forum.singtown.com/topic/558/常见问题-memory-error-fb-alloc-collision-内存不够与像素低

那这种问题没法解决吗?

2018-05-25 10:32
I
网红小智智 星瞳科技

不能从硬件上解决。

那就从软件上解决,有时候解决不了,视情况。