Tony,

Holy Jiminy Crickets!  There's some weird stuff goin' on in there!

Pure *integer* manipulations being done with string intermediaries?!  And
thus invoking memory offset calculations _AND_ the memory manager, which
could BLOCK on locking?! (in multi-threaded code).  Dr. Peter Below (and
others) gave us code something like 20 years ago to do in ONE assembly
instruction what the synutil.SwapBytes function is doing by taking the
scenic route. And does it about 60 TIMES faster (depending on the compiler,
processor, and which memory manager...)  That may not make too much
difference in most of this code (but could), but SwapBytes is also used in
synacrypt, where it probably makes a significant immediate difference...

(Unnecessary and incredible) Translations back and forth.  I'm getting dizzy
trying to figure out what's going on.


Geez Louise! Will you look at the 2-liner TBlockSocket.SendBlock() ?!?   I
mean I've cringed QUITE A BIT when I review MY OWN old code, BUT a library
like this should have the benefit of all our eyes "making all bugs shallow."
Huh, yeah. Kinda requires collaboration and cooperation.  I kinda squinted
on passing this code a few times before, over the years, but never really
looked at it with too much already on the table. Further inspection is
downright scary!

SendBlock() is BSWAPping (big/little endian flipping) the length data in
preparation for it being effectively BSWAPped back again in CodeLongInt()!
(And this is done in several other places.) Then look inside SwapBytes()
itself!  It's calling CodeLongInt() (with it's string and memory operations
to divide the bytes up, and doing math with them!), to prepare for calling
CodeLongInt()!!!  So there are multiple expensive calls to undo what
shouldn't be done in the first place. And then a somewhat expensive string
concatenation...  that is supposed to optimize the socket calls.

AND, OH YEAH... BY THE WAY... <g>  You are, or were, having a byte order
problem.


procedure TBlockSocket.SendBlock(const Data: AnsiString);
var
  i: integer;
begin
  i := SwapBytes(Length(data));
  SendString(Codelongint(i) + Data);
end;


>From synautil:

function SwapBytes(Value: integer): integer;
var
  s: AnsiString;
  x, y, xl, yl: Byte;
begin
  s := CodeLongInt(Value);
  x := Ord(s[4]);
  y := Ord(s[3]);
  xl := Ord(s[2]);
  yl := Ord(s[1]);
  Result := ((x * 256 + y) * 65536) + (xl * 256 + yl);
end;

Here are two immediate easy replacements for SwapBytes. The first is best
and fastest (~ 60x), but assembler, which may not be acceptable for all your
platforms, so I cobbled together a native Pascal version that should
probably be acceptable for all targets (FreePascal, etc...), and still about
40 times as fast as the current code.

{$WARN UNSAFE_CODE OFF}

function SwapBytes(Value: integer): integer; assembler;
asm // Change little-endian (Intel format) into big-endian (Motorola...) and
reverse...
  bswap eax
end;

function NonAsmSwapBytes(Value : integer): integer;
begin // Change little-endian (Intel format) into big-endian (Motorola...)
and reverse...
  result := (Value and $FF)     shl 24 or
            (Value and $FF00)   shl  8 or
            (Value and $FF0000) shr  8 or
            (Value shr 24);
end;



> I don't know if I will have time to do more testing.

Since you're not very interested, and I'm done trying to help where none is
wanted (in the Synapse lib), even on obvious, simple things (like misleading
500 default errors), AND I'm more than a little spooked by this code, it's
time for me to leave.  No wonder the more difficult topics I brought up
never got anywhere, when even the simple straightforward ones were either
ignored or argued about. [And it looks like Kylix support may be dropped
soon too, according to the survey on the Synapse main web page.]  That's it
for me. Like you, I'll just manage with the code I've got, or shop around
again.

I'll be sending in one or more financial contributions to the donations
page, but I'm done here. I'll probably be dropping this mailing list and
email account within a week. Can always look in the email archive to see if
anything's up.

Good Luck, and Bon Voyage <G> !!!


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to