Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: To good optimization?

  1. #1

    To good optimization?

    So I have a pretty simple function

    [pascal]function MyPoint(X,Y: Integer): TMyPoint;
    begin
    Result.X := X;
    Result.Y := Y;
    end;[/pascal]

    I can't see anything wrong with this, but when I test my project all my points ends up with coordinate (0,0). I try and add some breakpoints and can see that delphi can't acces variable X and Y due to optimization :?
    Can someone tell me what's going on?

    EDIT. Nevermind - it turns out the problem is not there.
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  2. #2

    To good optimization?

    Uncheck the Optimization in the Project/Options Compiler Tab
    and select Stack frames you will see the values

    CheGueVerra

  3. #3

    To good optimization?

    It's alway's a good idea to use Const.... like this:

    [pascal]
    function MyPoint(Const X,Y: Integer): TMyPoint;
    begin
    Result.X := X;
    Result.Y := Y;
    end;
    [/pascal]

    This will speed things up, especially mathy routines with lots of params.

    Just to let you know.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  4. #4

    To good optimization?

    Const with integers doesn't change the code generated.

  5. #5

    To good optimization?

    Quote Originally Posted by Setharian
    Const with integers doesn't change the code generated.
    But they clarify the code
    From brazil (:

    Pascal pownz!

  6. #6

    To good optimization?

    Const with integers doesn't change the code generated. Wink
    Hmmm... alway's thought it would speed things up... does it do so when using other types :? ?
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #7

    To good optimization?

    Quote Originally Posted by chronozphere
    Const with integers doesn't change the code generated. Wink
    Hmmm... alway's thought it would speed things up... does it do so when using other types :? ?
    When using const in parameters the function does not copy the parameter data to a local variable on the function, it actually works as a pointer to the original parameter data (or something like that)
    From brazil (:

    Pascal pownz!

  8. #8

    To good optimization?

    Const is for string, record and array parameters.

  9. #9

    To good optimization?

    You forgot interfaces and also sets larger than native integer size (4 bytes on 32-bit, 8 bytes on 64-bit).

  10. #10

    To good optimization?

    Ok.. assume this gets optimized to pointer even without const:
    [pascal]function MyPoint(X,Y: Integer): TMyPoint;
    begin
    Result.X := X;
    Result.Y := Y;
    end; [/pascal]

    But does compiler then recognize to not optimize this?

    [pascal]function MyPoint(X,Y: Integer): TMyPoint;
    begin
    X:=X+10; // If it was pointer it would modify origin...
    Result.X := X;
    Result.Y := Y;
    end;[/pascal]

Page 1 of 2 12 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
  •