C++ plugin to edit image

I’m trying to make a c++ and python plugin (something like texture paint tools), but it’s too slow because I have to rewrite pixel data (bpy.data.images[0].pixels) completely after every edit. How can this be fastened? Maybe I should send pointer to pixels array to c++? (c++ code is compiled as dll and loaded to python script)