-
Content Count
3710 -
Joined
-
Last visited
-
Days Won
185
Everything posted by David Heffernan
-
Leave it as an enum, but set the right enum size http://docwiki.embarcadero.com/RADStudio/Sydney/en/Minimum_enumeration_size_(Delphi)
-
You missed the language member. And probably the enum is actually an int and so 4 bytes.
-
I'm pretty sure that he chose to go to MS. And it looks like an inspired decision now. Look what he has built there.
-
When sorting a “StringList” is very costly
David Heffernan replied to dummzeuch's topic in Tips / Blogs / Tutorials / Videos
We've talked about this before I think. Stefan and I developed one for spring4d. You'll find it in the develop branch. As I'm sure you know, Timsort is stable. -
When sorting a “StringList” is very costly
David Heffernan replied to dummzeuch's topic in Tips / Blogs / Tutorials / Videos
These days I use Timsort for this reason. -
When sorting a “StringList” is very costly
David Heffernan replied to dummzeuch's topic in Tips / Blogs / Tutorials / Videos
You don't need a new control. You just need not to use it to store your data. Store your data in a non visual control. -
When sorting a “StringList” is very costly
David Heffernan replied to dummzeuch's topic in Tips / Blogs / Tutorials / Videos
Paying the price for using a GUI control to hold your data, rather than to view your data. -
Performance of MOVE vs + for concatenating mixed type values
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
The funny thing about this, is that the RTL code that implements a concatenation does this: Sum the length of all input strings. Allocate a new string of that length. Loop through all the input strings, moving their content to the new string. Return that new string. So even if this was your bottleneck, the RTL is already optimised!! In that original post that you linked, you were concatenating two strings, but repeatedly in a loop. So you had one allocation per expression. Here you have a single expression concatenating 11 strings. And that also has one allocation, because the RTL is, in this instance, not stupid. Bottom line is that your code using Move should be slower!! Please, please, please, take on board the lesson that optimisation starts with first identifying, with confidence, what your bottleneck is. If you can just take that lesson, then you will save lots of your time (and ours). -
Performance of MOVE vs + for concatenating mixed type values
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
It's like we are talking two completely different languages. -
Performance of MOVE vs + for concatenating mixed type values
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
What is unclear is why you wrote the code using Move in the first place, since there's no reason to believe that it addresses the performance bottleneck, which you seem not to have identified yet, or even attempted to identify yet. It's not that your questions are unclear, it's that you are asking the wrong questions. -
Performance of MOVE vs + for concatenating mixed type values
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
An explanation of why you start trying to improve performance without first identifying the performance bottleneck. -
Performance of MOVE vs + for concatenating mixed type values
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
Why don't you find out what the bottleneck is first? I simply don't understand why you keep making the same mistakes over and over again. -
Performance of MOVE vs + for concatenating mixed type values
David Heffernan replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
You aren't doing it effectively though, because you are still creating lots of intermediate string objects along the way. Your goal should be to create no intermediate string objects. In my own code which writes huge YAML files containing lots of numbers (both integer and floating point), I export without any heap allocation, without any intermediate string objects. I use functions like this: // disable range checks and overflow checks so that Abs() functions in case Value = Low(Value) {$R-} {$Q-} function CopyIntegerToAnsiBuffer(const Value: Integer; var Buffer: array of AnsiChar): Integer; var i, j: Integer; val, remainder: Cardinal; negative: Boolean; tmp: array [0..15] of AnsiChar; begin negative := Value<0; val := Abs(Value); Result := 0; repeat DivMod(val, 10, val, remainder); tmp[Result] := AnsiChar(remainder + Ord('0')); Inc(Result); until val=0; if negative then begin tmp[Result] := '-'; Inc(Result); end; Assert(Result<=Length(Buffer)); i := 0; j := Result-1; while i<Result do begin Buffer[i] := tmp[j]; Inc(i); Dec(j); end; end; {$IFDEF RANGECHECKSON}{$R+}{$ENDIF} {$IFDEF OVERFLOWCHECKSON}{$Q+}{$ENDIF} This performs the same job as IntToStr but writes to a user supplied buffer, rather than forcing a heap allocation and a new string. The user supplied buffer is stack allocated, and then gets pushed to the file using one of my buffered stream classes. I'm using ANSI characters here because the output encoding is UTF-8. I have similar code for floating point, but that's obviously much more complex. As an aside, this has the benefit that I can escape the tyranny of the RTL's broken code which converts between floating point and text. In summary though, I don't think you are going about this in the right way. You have not yet correctly identified the bottleneck in your code. I know I keep saying this, but it doesn't make it any less true each time I say it. -
Security - How freaky can you get!
David Heffernan replied to Clément's topic in Algorithms, Data Structures and Class Design
Whilst this is true, one should not be complacent and rely on it. A skilled hacker will have absolutely no trouble hacking your Delphi app if it is poorly designed. -
Security - How freaky can you get!
David Heffernan replied to Clément's topic in Algorithms, Data Structures and Class Design
Tampering with executables is pretty routine, and can be done for pretty much any program irrespective of the language it is coded in. The real question here is why the target was running a tampered executable in the first place. That seems like the real source of the problem, not that the original executable was written in Delphi. If your new customer thinks that the problem will be solved by writing programs in "safe" languages then he/she is delusional. Once you let an attacker execute their code in your computer, the game is over. -
The Case of Delphi Const String Parameters
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
If the tool was clever it would only object when the parameters were both passed by reference -
Round() appears to be non-deterministic
David Heffernan replied to Thijs van Dien's topic in RTL and Delphi Object Pascal
There's no silver bullet here. You have to find every call that can potentially change the control state, and restore it when that call returns. Plus you've got the broken Delphi RTL which means that a change of control state in one thread can leak into another thread. It's worse on x64 than x86. I've discussed this here many times before. Emba know about the issues and have chosen not to address them. I've told them how to fix the issues in the RTL. In my code base I've replaced a number of RTL functions with thread safe versions, and added protection for whenever my code calls into external libraries. No silver bullet. -
Round() appears to be non-deterministic
David Heffernan replied to Thijs van Dien's topic in RTL and Delphi Object Pascal
Could be all sorts of things. Calling almost any external module could change the control state. It's very hard to track it down. -
Round() appears to be non-deterministic
David Heffernan replied to Thijs van Dien's topic in RTL and Delphi Object Pascal
Round is deterministic. Remember though that its input is its argument, and the floating point control state. -
The Case of Delphi Const String Parameters
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
That would then be a race condition between the copy and the modification. That seems like the far bigger issue. -
The Case of Delphi Const String Parameters
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Nothing to see here. Carry on using const for string parameters. The issue is vanishingly rare. If you encounter the issue, fix it. Don't go changing existing code unless you are actually affected by the issue. -
Range Check Error - what actually happens
David Heffernan replied to david_navigator's topic in Algorithms, Data Structures and Class Design
Not so. In fact set of Char is actually implemented as set of AnsiChar. It has very special treatment introduced to "help" porting from ANSI Delphi to Unicode Delphi. -
Is your question, "is it possible to change the focus without changing the active window?"
-
Range Check Error - what actually happens
David Heffernan replied to david_navigator's topic in Algorithms, Data Structures and Class Design
Unfortunately Emba never implemented proper generics support for sets which would make this trivial and type safe. -
Range Check Error - what actually happens
David Heffernan replied to david_navigator's topic in Algorithms, Data Structures and Class Design
The issue is that you need to write this code for every single set type that you use.