Stop being the product.
Become the owner.
or
sign uplog in

How to load large files into memory in c I'm using a…

How to load large files into memory in c

I'm using a library that interacts with mpd (the music player) and have to use a function to receive the album art of a song, but the function only provides part of the the image at a time, receiving the full file over multiple function calls.

(libmpdclients's mpd\_run\_albumart() for those interested)

using malloc in this scenario, and assuming I don't know the file's size to begin with, what's the best way to do this?

Should I just malloc an arbiritarily large amount and fill it - seems very naiive.

Should I malloc an extra block of memory for each function call (I know the max amount i can receive per function call) - but surely this memory could be non-contiguous and cause problems?

Allocate a bit of memory -> function call and fill it -> if that's not the full image, then allocate a new bit of memory = to current size of the file+size of another incoming package -> copy the existing data in & free the old block -> repeat until the whole things' free?

Seems like a hell of a lot of malloc and free() calls though, would this too taxing?

What do people think?

Thanks so much in advance!
#dev #programming #technology
earnings
2,000 mlx total
$0  total
engagement
2 views
0 reactions

0 comments