Results 1 to 5 of 5

Thread: typcasting

  1. #1

    typcasting

    ive got a class called TRGLPhysicsObject (class of TObject) and a pointer to that class, whats faster (or whats best)...

    Code:
    var
     LPhysicsObject: TRGLPhysicsObject;
     LPointer: Pointer;
    
    Begin
      LPhysicsObject := LPointer;
    
      LPhysicsObject.bla := 123;
    or

    Code:
    var
      LPointer: Pointer;
    
    Begin
      TRGLPhysicsObject(LPointer).bla := 123;
    just wondering because a callback went horribly wrong then i changed a few things and now it works fine

  2. #2

    typcasting

    When i use pointers i find it easier to type cast it as:
    [pascal]
    type
    PRGLPhysicsObject = ^TRGLPhysicsObject;
    TRGLPhysicsObject = Class(TObject)
    // code
    end;

    ////

    var
    LPhysicsObject: PRGLPhysicsObject;
    begin
    LPhysicsObject.bla := 123;
    [/pascal]
    This way you can use all the functions and propertise in that type..
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  3. #3

    typcasting

    but you would still have to assign it wouldnt you, or is it faster to assign it to a PRGLPhysicsObject instead of a TRGLPhysicsObject?

  4. #4

    typcasting

    Tux, the cast takes no time in compiled code, it is resolved by the compiler.
    The assignement instead would take an extra instruction but i'm confident that the optimizer can figure it out that it's unnecessary and can be removed.
    So at the end it shouldn't be different.

    Also, i always suggest to avoid thinking too much on almost this type of micro-optimization when maybe in other part of the program there's some nested loops or such that loses hundred of times more than the assignement.

    BTW i never see the use of a pointer to a class, as in
    M109uk code.. Classes are already pointers.
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  5. #5

    typcasting

    thanks, i keep forgetting the compiler knows best

    in that case im not sure what i did to stop the code falling to 2fps :/

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
  •