Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28

Thread: My First 3D Game

  1. #11

    My First 3D Game

    Any time you modify a string, mostly when adding to it, it has to reallocate the memory for that string. This usually involves a new memory allocation, copy the contents of the old string to the new buffer, then free the old memory buffer. Look at this over the lifetime of an application and you are talking about potentially millions of tiny memory allocations and frees.

    If you ever declare variable as a string or a dynamic array in a function, the compiler secretly adds a try..finally block around the entire function to free the memory used by those strings and dynamic arrays. That takes extra CPU time to execute each time the function is called.

    TObject, the base class for every class, contains string members. The process to create an instance of a TObject-derived class is quite expensive. The creation of each instance of a TObject-derived class involves multiple calls to InstanceSize(), which then allocates the memory for that instance. It then sets that memory to zero. It then performs a while loop, inside which is a for loop, to setup the interface table for that class instance. Remember, this is for each instance of the class that you create. There are similar expenses when destroying the class instance.

    Unless you override some base methods in TObject, there is also no way to bulk-allocate a bunch of class instances. Each class instance must be created individually. That is horribly expensive when you might be talking about using a class for a vector or matrix. A mesh might have 10,000 vertices. That is a lot of needless overhead, and the time wasted can be noticed by the end user in longer load times.

    As I said, this comes from having a commercial games development, and the amount of overhead in using TObject and strings rings alarm bells in my head.

  2. #12

    My First 3D Game

    Does TObject have String members? if you look the code in the System unit it only has methods, and InstanceSize returns only 4 bytes.
    sorry for my English.....

  3. #13

    My First 3D Game

    Ahh, got that bit wrong. The class itself doesn't have strings as members (the four bytes is a pointer to a virtual method table). The virtual method table (one table for each class) contains strings, but these are of the ShortString type.

  4. #14

    My First 3D Game

    Quote Originally Posted by Sly
    Unless you override some base methods in TObject, there is also no way to bulk-allocate a bunch of class instances. Each class instance must be created individually. That is horribly expensive when you might be talking about using a class for a vector or matrix. A mesh might have 10,000 vertices. That is a lot of needless overhead, and the time wasted can be noticed by the end user in longer load times.

    As I said, this comes from having a commercial games development, and the amount of overhead in using TObject and strings rings alarm bells in my head.
    Perhaps if you had the same experience with C/C++ (please, don't throw any rocks), you should know that creating a class for each primitive like point or vector might not be a very good idea considering the performance.

    Many libraries I have seen and have worked with, including Asphyre (which I am developer of) use clases to represent a single-instance objects like Canvas and use records and record arrays to store points, vertices, normals, matrices and so on. In fact, in my Asphyre library, there are primitive storage classes like TVectorList, which stores an array of TVector4 records and have method like Transform, which receives a pointer to the matrix and then multiplies all vectors in array either using a multiplication procedure (which is not part of any class), or using a batch procedure, which uses SSE to transform all vectors. No offence, but I really think you should review the libraries and how they work before doing really serious claims.

  5. #15

    My First 3D Game

    Thanks for the explanation Sly. Very informative.



    Quote Originally Posted by Lifepower
    No offence, but I really think you should review the libraries and how they work before doing really serious claims.
    No need to...

    Quote Originally Posted by Sly
    Most engines I have seen, especially for Delphi, heavily use classes and dynamic strings.
    Could be that yours was not among those Sly used.

  6. #16

    My First 3D Game

    Quote Originally Posted by Traveler
    Quote Originally Posted by Sly
    Most engines I have seen, especially for Delphi, heavily use classes and dynamic strings.
    Could be that yours was not among those Sly used.
    This was written in Asphyre forum on 11 of July, 2005:
    Quote Originally Posted by Sly
    I was involved with Powerdraw when it was first released, and contributed a few fixes to it. However I never continued with it. I've always considered the use of components or heavy use of Delphi classes to be overkill and quite inefficient. Maybe that comes from my console development background where you have to be careful about every function call that you make.
    I think Sly *is* referring to Asphyre and I would like to see the proof, that the usage of classes in Asphyre makes it inefficient.

  7. #17

    My First 3D Game

    Quote Originally Posted by Sly
    Unless you override some base methods in TObject, there is also no way to bulk-allocate a bunch of class instances. Each class instance must be created individually. That is horribly expensive when you might be talking about using a class for a vector or matrix. A mesh might have 10,000 vertices. That is a lot of needless overhead, and the time wasted can be noticed by the end user in longer load times.
    This is exactly what i did for my engine, I created a TFastObject which just alocates memory and sets up the VMT but that's it, the performance increase just by doing that was very significant. I also tested allocating 10000's obf objects in an array by pre allocating the memory using a Frame Memory manager, again the performance was significantly improved.

    I tend to use records for things like verties and normals as they tend to be easier to pass into opengl, but I always use objects for my engine, but since I derived from my TFastObject things work allot faster
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  8. #18
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    My First 3D Game

    If anyone is interested in my progress:

    http://www.cairnsgames.co.za/downloa...on-Install.zip (0.9MB)

    Each to their own I say. I WILL use classes and long strings becuase it makes my life easier.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  9. #19

    My First 3D Game

    technomage, could you explain a bit more the implementation of your TFastObject, or show some code? it seems very interesting.

    Thanks!
    sorry for my English.....

  10. #20

    My First 3D Game

    I decided to write a short information sheet on the implementation of TFastObject over at Cerebral-Bicycle, you can read the article here

    Hope you find it usefull, if there is enough interest I'll post the stuff on a Frame Memory manager at some point and how it links into the TFastObject to make creating 1000's of objects even faster.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •