Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

free() blocking other threads, system slowdown

I'm working on a multithreaded plugin. When I do a free() on quite large blocks of memory ( > 10 MB ) the application with my plugin temporarily slows down too much. ( Its an audio app, the audio thread gets too less time ). I'm not sure if the free() is using a lot of CPU or that it is blocking other threads way too long. Its seems that a call to madvice() is doing a lot of work. I'm used to free() taking up not much time ( it does not when I run in 32 bits mode ).

some info: OSX 10.8 64 bits plugin & program C++

Any suggestions on how to continue are very welcome.

like image 780
jankoen Avatar asked Nov 01 '22 14:11

jankoen


1 Answers

One obvious suggestion would of course be to stop doing the free() (which should be some form of delete in C++, by the way).

Don't free the memory as long as your plugin is still loaded and active (or maybe "running"), free the resources when the plugin no longer needs to be around.

If you need to re-allocate a new buffer after freeing the old, figure out a way to re-use the already allocated memory, instead.

like image 50
unwind Avatar answered Nov 09 '22 23:11

unwind