Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


pb of memory

This topic is 5943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, I have a problem of memory with my program it runs. I use a class Vector2D which overload the operator +. Vector2D Vector2D::operator +(Vector2D aVector2D) { Vector2D* vResult = new Vector2D(); int angle; vResult->x = GetX() + aVector2D.GetX(); vResult->y = GetY() + aVector2D.GetY(); angle= -1; //tan-1(vResult.y/vResult.x); vResult->length=sqrt((double)vResult->x + vResult->y); return(*vResult); } As you can see there is a vector2D variable ( vResult) created which is probably my problem. I can''t delete it because this is the result returned. the problem is in my mind that I create many times a variable with the operator new but I don''t delete it. How can I resolve this problem? thank you!!!!

Share this post

Link to post
Share on other sites
why do you dynamically allocate memory for that vector anyway?
Just do Vector2D vresult; vresult.x = ... return vresult.
And another thing: obviously you allow direct access of x and y (vresult->x = ... ) but why do you then use Get() functions?
For something that propably is used often in timecritical situations like a vector you shouldn''t deal with the overhead of Get() functions.
And still one more thing: change your function to
Vector2D Vector2D::operator +(Vector2D &aVector2D) and pass the param by reference so you dont make a temporary copy of that vector

Just my 2 cents

Runicsoft -- home of my open source Function Parser and more

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!