Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 06/01/21 in Posts

  1. Any branching (if, case) is expensive - especially when it cannot be predicted because you have a random pattern. Here is how it's done fast: procedure CountAllItems4(const aDocuments: TDocuments; var counts: array of Integer); var i: integer; begin counts[0] := 0; counts[1] := 0; counts[2] := 0; for i := Low(aDocuments) to High(aDocuments) do Inc(counts[Ord(aDocuments[i].DocType)]); end; var counts: array[TDocType] of Integer; begin ... CountAllItems4(vDocuments, counts); q := counts[dtQuote]; o := counts[dtOrder]; i := counts[dtInvoice];
  2. Remy Lebeau

    UDP sending and receiving

    You don't need to Listen() on a UDP socket. Only Bind() it, and then ReceiveFrom() on it. Listen() is only used for TCP. You can't Bind() to a broadcast IP, only to a local IP.
  3. Remy Lebeau

    UDP sending and receiving

    Connect()'ing a UDP socket assigns the specified peer IP/port as a static association, so that subsequent sends always go only to that peer, and only packets from that peer can be received. It also enabled better error reporting. If a send fails with an ICMP error, such as host/port unreachable, a subsequent send/read can fail with an appropriate error code. On a Connect'ed socket, you can use Send() and Receive(), you are not restricted to SendTo() and ReceiveFrom().
  4. 1) As long as you don't need input value of Counts, it's better to mark it "out" instead of "var" 2) When you declare a type for counts, you can zero it with "Default": "counts := Default(TCounts)"
  5. +1 Small modification: Counts: array[TDocType] of Cardinal ..zeroize the array... for i := Low(aDocuments) to High(aDocuments) do Inc(counts[aDocuments[i].DocType]);
×