freeTrajInfo.c 904 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "freeTrajInfo.h"
  2. void freeTrajInfo(cmscp_trajInfo** traj, cmscp_setup* setup, int level)
  3. {
  4. // 释放cmscp_trajInfo结构体空间
  5. // level 为 0 的时候只释放2级下的内存
  6. // level 大于 0 的时候全部释放
  7. int iphase;
  8. if (traj)
  9. {
  10. if (level >= 0)
  11. {
  12. for (iphase = 0; iphase < setup->numPhase; iphase++)
  13. {
  14. freeTrajInfoPhase(traj, setup, iphase);
  15. }
  16. }
  17. if (level > 0)
  18. {
  19. free(traj);
  20. }
  21. }
  22. }
  23. void freeTrajInfoPhase(cmscp_trajInfo** traj, cmscp_setup* setup, int iphase)
  24. {
  25. if (traj[iphase])
  26. {
  27. if (traj[iphase]->control)
  28. {
  29. if (traj[iphase]->control->v)
  30. {
  31. free(traj[iphase]->control->v);
  32. }
  33. free(traj[iphase]->control);
  34. }
  35. if (traj[iphase]->state)
  36. {
  37. if (traj[iphase]->state->v)
  38. {
  39. free(traj[iphase]->state->v);
  40. }
  41. free(traj[iphase]->state);
  42. }
  43. if (traj[iphase]->parameter)
  44. {
  45. free(traj[iphase]->parameter);
  46. }
  47. free(traj[iphase]);
  48. }
  49. }