1

I'm currently working on a image server project in Python and I've been unable to find information on the most efficient way of storing the images in memory. I've tried using sys.getsizeof to try to get the size of the object in memory, but it doesn't return an accurate size for numpy arrays or PIL images. I've also thought about bypassing Python modules all together and storing the images in a tmpfs ramdisk and loading them back in when the images are requested. I'd appreciate any insights into the best practices for this problem.

Jade Sage
  • 11
  • 2
  • `getsizeof` is pretty good at giving the size of `numpy` arrays, though you could also use `nbytes`. It will also reflect the `np.save` size, because that essentially saves a copy of the array's data buffer. There's no compression - just a straight save of the data. But that may not be true for other image storing methods. – hpaulj May 05 '22 at 21:31
  • 2
    There are not nearly enough details here to be able to answer you. The most efficient way of storing images is obviously when they are compressed. But you give no indication of what type of images you are storing, nor for how many clients, nor why they can't be stored on disk? – Mark Setchell May 05 '22 at 22:21
  • You could try saving it as a base64 screen and convert it when read back in. [PIL image to b64](https://stackoverflow.com/questions/31826335/how-to-convert-pil-image-image-object-to-base64-string) – zodiac508 May 05 '22 at 22:21

0 Answers0