Added implementations for cvSetMemoryManager and some related APIs (Feature #3074)
From the original pull request (https://github.com/Itseez/opencv/pull/830):
1. Provide the implementation for cvSetMemoryManager(). cvRemoveMemoryManager() is also added but it just simply switches the memory manager to the default allocator/deallocator, i.e. system malloc/free. Currently the code limits the number of user-defined memory managers to 1022.
2. Allow users to activate memory pool at runtime. Currently in opencv, if we want to activate the memory pool, we need to remove "#define CV_USE_SYSTEM_MALLOC" in alloc.c and then recompile opencv. In this patch, we can activate the memory tool by involving cvTurnOnMemoryPool(). Also we can turn off it via cvTurnOffMemoryPool(). When calling cvTurnOnMemoryPool(), users can specific the block size used in the memory pool (if an object's size is larger than block size, it will be allocated by system malloc/free).
However currently it doesn't allow to change the block size. That is to say, if the memory pool is turned on, it can only be re-turned on with the same block size.
3. The code doesn't allow user to apply different memory manager to different threads. If this feature is needed, we may need to change lots of code in opencv's basic structure and may result in lots of problems.