[RFD] Pointer management

Discussions related to programming Transport Empire.

Moderator: Transport Empire Moderators

Post Reply
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

[RFD] Pointer management

Post by Hellfire » 26 Sep 2005 12:11

I've been working a lot with Java lately, and the thing I like best about Java is its garbage collector. The idea that I can create objects, use them and forget about them when they're not needed anymore is quite pleasing.

This brings up the issue of Pointer management. We should definitely have some guidelines on how to handle pointers, because if we don't, we will very likely end up with one big memory-leaking mess.

I have an idea for intelligent pointers, which allow (incremental) garbage collection, but I won't bore you with details unless you're interested to hear.

Disclaimer: I probably invented a wheel that has been invented many times before, but still, I'd like to hear your ideas and views on pointer management and/or garbage collection
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...

User avatar
uzurpator
Transport Empire Moderator
Transport Empire Moderator
Posts: 2134
Joined: 10 Jan 2003 12:21
Location: Wroclaw, Poland / Katowice, Poland

Post by uzurpator » 26 Sep 2005 12:52

Maybe we should simply use one of c++ garbage collectors? Or overload new/delete words?
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.

Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post by Hellfire » 26 Sep 2005 13:07

I'm not suggesting that we should use a garbage collector or that we should not. I'm interested to know other people's opinions on garbage collectors. And similarly on pointer management.

Of course, using garbage collectors has some pros and cons. It gives greater freedom in programming at the expense of some extra memory usage and (sometimes) decreased performance.
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...

User avatar
uzurpator
Transport Empire Moderator
Transport Empire Moderator
Posts: 2134
Joined: 10 Jan 2003 12:21
Location: Wroclaw, Poland / Katowice, Poland

Post by uzurpator » 26 Sep 2005 16:19

My opinion:

Garbage collector - good for sloppy programming, bad for speed, increases memory needs.
Overloaded operators - something in between
Manual memory management - fastest, but more buggy

Imho in speed oriented tasks we should use manual management, the rest can get away with a garbage collector
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.

Grunt
Route Supervisor
Route Supervisor
Posts: 449
Joined: 03 Oct 2003 20:22
Location: Edmonton, Alberta
Contact:

Post by Grunt » 26 Sep 2005 20:48

We are dealing with a real time game here - the speed penalty from using a garbage collector will be unacceptable, I feel.
Grunt
(aka Stephan Grunt, CEO of Grunt Transport Inc. since 1994.)

fujitsu
Engineer
Engineer
Posts: 32
Joined: 12 Jul 2005 08:14
Location: Melbourne suburbs, Victoria, Australia (GMT+10)

Post by fujitsu » 26 Sep 2005 23:52

Yeah, I have always used manual management, but that is just the way I like to do things. Is the performance benefit big enough to turn us off using garbage collectors? Maybe we should run some tests...

William.

User avatar
uzurpator
Transport Empire Moderator
Transport Empire Moderator
Posts: 2134
Joined: 10 Jan 2003 12:21
Location: Wroclaw, Poland / Katowice, Poland

Post by uzurpator » 27 Sep 2005 06:21

fujitsu wrote:Is the performance benefit big enough to turn us off using garbage collectors?
Think Java...
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.

Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post by Hellfire » 27 Sep 2005 08:08

Java has more performance issues than just the garbage collector. ;)
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...

fujitsu
Engineer
Engineer
Posts: 32
Joined: 12 Jul 2005 08:14
Location: Melbourne suburbs, Victoria, Australia (GMT+10)

Post by fujitsu » 27 Sep 2005 08:56

Hellfire wrote:Java has more performance issues than just the garbage collector. ;)
Yeah, let's see: It is byte-code interpreted... It is evil... It was created by Sun... Java = evil and slow.

William.

User avatar
uzurpator
Transport Empire Moderator
Transport Empire Moderator
Posts: 2134
Joined: 10 Jan 2003 12:21
Location: Wroclaw, Poland / Katowice, Poland

Post by uzurpator » 27 Sep 2005 22:11

Ok - so it is settled - we are hard to the core and will use manual management.

Or not?
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.

fujitsu
Engineer
Engineer
Posts: 32
Joined: 12 Jul 2005 08:14
Location: Melbourne suburbs, Victoria, Australia (GMT+10)

Post by fujitsu » 28 Sep 2005 09:43

uzurpator wrote:Ok - so it is settled - we are hard to the core and will use manual management.

Or not?
I think speed is of the essence in such a game, so we should use manual management. I guess we just need to make sure that we delete everything we create, or we will run into... large issues. It can be a bit of a bother, but in the long run is cleaner and faster. And clean and fast is good!

William.

Grunt
Route Supervisor
Route Supervisor
Posts: 449
Joined: 03 Oct 2003 20:22
Location: Edmonton, Alberta
Contact:

Post by Grunt » 28 Sep 2005 13:43

fujitsu wrote:[W]e just need to make sure that we delete everything we create, or we will run into... large issues.
Of course, if we miss something, our gamers will be more than happy to point this out to us. :)
Grunt
(aka Stephan Grunt, CEO of Grunt Transport Inc. since 1994.)

fujitsu
Engineer
Engineer
Posts: 32
Joined: 12 Jul 2005 08:14
Location: Melbourne suburbs, Victoria, Australia (GMT+10)

Post by fujitsu » 28 Sep 2005 22:06

Grunt wrote:
fujitsu wrote:[W]e just need to make sure that we delete everything we create, or we will run into... large issues.
Of course, if we miss something, our gamers will be more than happy to point this out to us. :)
I think so.

Topic: "TE uses huge amounts of memory"... I can just see them there now :)

William.

Jeremia
Engineer
Engineer
Posts: 2
Joined: 25 May 2009 17:21

Re: [RFD] Pointer management

Post by Jeremia » 25 May 2009 17:51

Hi Folks,

have you allready thought about using smart pointers? In my opinion it is a good mechanism for not using garbage collection, but forgetting about memory leaks at the same time. Since every class handles it's instances with reference counting. I love to use this mechanism for classes which are normaly instanciated a lot of times likes a matrix class. Another nice thing is, that this allows you to return references of objects with no problem. So you don't need to pass an object to a method if you wan't to write to it.

What do you think about using smart pointers for several classes?

Best regards

Jeremia

DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: [RFD] Pointer management

Post by DaleStan » 26 May 2009 02:27

Moon instructs a student

One day a student came to Moon and said: “I understand how to make a better garbage collector. We must keep a reference count of the pointers to each cons.”

Moon patiently told the student the following story:

“One day a student came to Moon and said: ‘I understand how to make a better garbage collector ...
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser

Post Reply

Return to “Transport Empire Coding”

Who is online

Users browsing this forum: No registered users and 1 guest