Now I am dealing with some Xlib programming and want to take screenshots frequently and efficiently.
It seems that
I want to use pre-allocated memory buffer in order to avoid massive memory allocation. Is there any way to do so?
You should use
XGetSubImage it works with previously defined XImage and this way you can reuse the image.