free array of array extremely slow

This is a discussion on free array of array extremely slow within the C++ Programming forums, part of the General Programming Boards category; hello all,
i ve created an array of array, and it is VERY fast to allocate with new.
however, when ...

free array of array extremely slow

hello all,

i ve created an array of array, and it is VERY fast to allocate with new.

however, when freeing it with delete, it takes up to 1 minute! i can actually see the size decreasing slowly in the Page File Usage History of the Windows Task Manager (whereas when created it is an almost instant jump in memory size)

i ve been suggested that this could be because the compiler kinds of defragments the memory everytime it frees just one column, whitout realizing that it would eventually free the WHOLE thing anyway...

any idea to make the delete faster (i hope as fast as when created with new)

Also note that your delete calls are wrong. You should be using delete[] instead of delete in some places depending on how you allocated the arrays. This might not make it go any faster, but it is still a good idea to make it correct first.

The memory fragmentation thing can be handled with a pool allocator in a standard container, or by taking advantage of the small block heap. A co-worker of mine found an issue where Microsoft turned off their small block heap allocator in Win 2K and later. When he called _set_sbh_threshold(1016) at the beginning of the program to turn that back on, it improved the memory freeing times in the app immensely. You might consider trying this in your app, but I don't have any extra information on other consequences or pitfalls.

If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

>and why is "register" useless?
It's only useless on compilers that ignore it.

>since it was keeping the value in the register of the processor
Using register is only a hint, one that the compiler can ignore, and almost always does, because register assignment is an optimization that the compiler is better suited to doing than the programmer.

>btw, adding the [] did not change the speed of "delete".... still terribly slow :-(
I don't imagine that it did, but it made your code correct where it was otherwise completely undefined. When you allocate memory using operator new[], you have to use operator delete[] to deallocate it or it invokes undefined behavior, which is a synonym for "really really wrong". Likewise, when you allocate a single object with operator new, you have to use operator delete to deallocate it: