I am writing python code that merges large files at different points. I did something similar in C, where I allocated a 1 MB char array and used it as a read / write buffer. And it was very simple: read 1MB into a char array, then write it.
But with python, I assume this is different, every time I call read () with size = 1M, it selects a character string of length 1 M. And, I hope when the buffer goes out of scope, we will free it on the next gc-aisle.
Will python handle the distribution this way? If so, is the constant allocation / release cycle calculated expensive?
Is it possible to tell python to use the same memory block as in C? Or is python vm smart enough to do it yourself?
I assume that I am mainly aiming that this is similar to the python dd implementation.
source share