Loading DjVu files of many pages causes serious memory fragmentation and it might results in slowness on delete calls. You can ease the condition to some extent by using Chunk::compact method. The method linearize the memory use of the Chunk instance.
Even with such tricks, if you suffer from severe memory fragmentation, you can use LFH on Windows. For more information, see delete/delete[] calls are too slow on my code .
Basically, on Linux machine (but it's also true with future OS X machine), we should explicitly specify the compiler to build the codes by CXX variable like the following commandline:
Please check your compiler settings, without /GR option, you may happen to get such result. For more information, see Windows Development Notes.
In general, global variables are initialized before execution of some initialization codes and also before main()
. Since String depends on initialization of some components, it should not be used before them and it could not be a global variable.
Anyway, if it could not be non-global variable, there is a way to make it fake-global variable:
On some memory condition, especially on multithreading code, memory allocation/releasing codes cause much fragmentation of memory blocks due to its frequent use of small memory blocks and it makes the delete
calls so slow.
On Windows XP or later (and also Windows 2000 with a hotfix), there's a mechanism to improve such situation, named low-fragmentation heap. You can enable this by inserting the following code to your startup routine or code which is executed in relatively earlier stage/phase of your code:
There're still several notices for this code:
_get_heap_handle function was introduced on Visual C++ 8.0 (Visual Studio 2005) so this code block should be ifndef-ed for earlier compilers.For further improvement, MemoryAllocator is the last resort; implementing your own allocator to completely isolate SDK's heap. The following code is a sample of custom allocator to use native Windows heap:
Anyway, please don't forget to call MyIsolatedMemoryAllocator::init()
on your startup code.
SimpleArray throws exceptions of errOutOfMemory if the underlying MemoryAllocator instance cannot allocate memory due to some situation.
The built-in allocator uses std::malloc to allocate memory and the actual condition depends on the operating system and C/C++ runtime library.
To debug the memory allocation, you can change it by MemoryAllocator::setDefault function but much care should be taken for global/static objects before replacing the allocator.
The following is a sample code to replace the allocator:
For more realistic MemoryAllocator sample, see delete/delete[] calls are too slow on my code.