-2

i'm writing this because i'm noticing that when i need to sort a list of n elements, my ram usage keeps growing even if all the elements are allocated and the only operations requested are swapping and moving elements...

The problem is not the speed of my algorithm, but the fact that on every new cycle a lot of ram gets allocated, and i don't understand why, could you please help me?

Thanks!

Francesco Rizzi
  • 631
  • 6
  • 24

1 Answers1

1
  1. Write a test with 10 elements in the sequence
  2. Run it under valgrind --tool=massif ...
  3. Profit

There are tons of sorting algorithms and containers implementations around, many (if not most) container implementations allocate/deallocate memory on each insert/erase operation, so you really need to go all the way down to finest details and pick the right combination if dynamic allocation is a problem.

bobah
  • 18,364
  • 2
  • 37
  • 70