memory.txt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Memory Management for Crown
  2. (mostly based on "Building your own memory manager for C/C++ projects" by IBM)
  3. === Why ===
  4. * Improves application performance
  5. * Allows to avoid memory leaks
  6. * Can take care of memory corruption and other kind of errors hard to be detected in normal circumstances
  7. * Allows memory tracking (profiling and statistics)
  8. === Goals ===
  9. * Speed
  10. * Must be faster than the compiler-provided allocators
  11. * Must provide optimized allocators for allocation patterns that occur frequently in the code
  12. * Robustness
  13. * Must return all the memory it requested to the system
  14. * Must handle erroneus cases and bail out gracefully
  15. * Fragmentation control
  16. * Must provide effective ways to reduce fragmentation at minimum
  17. * Debugging support
  18. * Must provide some debuggin informations and corruption checking system
  19. * Must be able to track memory usage and collect statistics
  20. === Implementation details ===
  21. * Free-lists based memory manager with allocators based on common strategies
  22. === Development log ===
  23. * Tue Jan 18 - First attempt
  24. * I spent the last 4 hours trying to build a very simple memory manager based on the so called 'free-lists'.
  25. * Only an advice: DO NOT TRY TO MANAGE THE LISTS WITH A List. :D
  26. * I replaced List with the STL's list (doubly-linked list) and now it works decently. I've figured out
  27. * that it's all about free-lists management. We need a fast management method based on fast data structures.
  28. * The current implementation performs as follow:
  29. *
  30. * === Default memory management ===
  31. * (De)alloc count: 10000000
  32. * Time: 916ms
  33. * === Custom memory management ===
  34. * (De)alloc count: 10000000
  35. * Time: 1290ms
  36. *
  37. * Which is pretty crappy, about 1.4x slower despite needing only 2 context switches versus approx 10000000... :|
  38. * There's clearly something wrong.
  39. *
  40. * !!! UPDATE !!!
  41. *
  42. * Seems that using std::list to emulate what std::stack is designed for has not been a great idea. The same
  43. * code running with the latter is much (6.2x) quicker:
  44. *
  45. * === Default memory management ===
  46. * (De)alloc count: 10000000
  47. * Time: 973ms
  48. * === Custom memory management ===
  49. * (De)alloc count: 10000000
  50. * Time: 208ms
  51. *
  52. * Haha! Now we are "faster than a fucking tornado." (cit.) but unfortunately it's only the beginning, there's
  53. * a ton of work to be accomplished. Anyway, nice to see some progress!
  54. *