-
Content Count
3711 -
Joined
-
Last visited
-
Days Won
185
Everything posted by David Heffernan
-
Prefix unit local variable names
David Heffernan replied to Mike Torrettinni's topic in General Help
a is for argument -
We still have basically no idea what you are asking.
-
Integer overflow in tStringList.SaveToFile
David Heffernan replied to Jud's topic in RTL and Delphi Object Pascal
Generally it's wise to try not to do this. -
There are countless ways in which Delphi code may be involved in web development. If you want anybody to spend their time helping you I suggest that you spend more of your time thinking about your problem, and specifying in more detail what specifically you need help with.
-
is it possible to undeclare an identifier?
David Heffernan replied to dummzeuch's topic in General Help
No -
Integer overflow in tStringList.SaveToFile
David Heffernan replied to Jud's topic in RTL and Delphi Object Pascal
This has been answered above. It's the use of an intermediate string variable that holds the entire text which is then saved. And strings have 32 bit length. I'm not sure what @emailx45 is getting at but the problem you face is not due to a shortage of memory or address space. It's just that the string length is stored in a 32 variable. And a string is used by SaveToFile to save the text. FWIW, it seems wasteful to me to make an in memory copy of GBs of text just to save it. I'd be looking for a writer based approach. Just not using the raw RTL classes because of their dire performance. -
What exactly is your rationale for wanting to use multiple engines? Why is it not possible to do this with a single engine?
-
Generic record helper for enumeration types
David Heffernan replied to chkaufmann's topic in RTL and Delphi Object Pascal
You can't have generic helpers. -
Integer overflow in tStringList.SaveToFile
David Heffernan replied to Jud's topic in RTL and Delphi Object Pascal
You don't need the if. You know that sList is not nil. Also, Free already includes a nil check. Also, there is the <> operator for not equals. -
Integer overflow in tStringList.SaveToFile
David Heffernan replied to Jud's topic in RTL and Delphi Object Pascal
Is your executable compiled with the overflow checks compiler option enabled? -
Integer overflow in tStringList.SaveToFile
David Heffernan replied to Jud's topic in RTL and Delphi Object Pascal
In what way? Can you be more specific. As for the main problem, I'm not surprised. I'd expect that you'd be better off using a stream writer to write such a huge collection to a stream. I'd submit a bug report to QP, in case on doesn't already exist, and then write some helper code to workaround the issue. -
Maybe, but I'm still using XE7 which is why my own code doesn't use the RTL string helper.
-
https://quality.embarcadero.com/browse/RSP-10041 https://quality.embarcadero.com/browse/RSP-11302 Here are a couple of examples, but there are more.
-
Good point. But I'm using XE7 and the string helper has many many bugs, including I believe in one of the split or join functions. Plus, my version minimise heap allocation.
-
I mean. I'd start by using TRegistry. And I'd write the code myself rather than hacking at scraps found from the web.
-
I'm sure you will be able to debug it. Good luck.
-
Best to be clear on what you are doing here. The code seems to assume ANSI. Again are you using ANSI text?
-
Once you get to the first double null then the rest of the data should be ignored. I'd remove everything after the first double null and then your original idea will work. You'll need to make sure you add back a double null terminator when you write it back. Are you really using ANSI text?
-
I doubt that what your posted in your original post really is a REG_MULTI_SZ. That really is double null terminated rather than null separated.
-
Manage overloaded IfThen functions
David Heffernan replied to Mike Torrettinni's topic in General Help
This is pretty flaky mind you. Sometimes type inference works, sometimes it doesn't and you have to be explicit. It is something that may have improved in more recent releases, but IIRC some issues remain. -
Manage overloaded IfThen functions
David Heffernan replied to Mike Torrettinni's topic in General Help
I'm not sure what looking through assembly would tell you. If performance was your motivation then you'd time the code in a realistic setting, and if it was a hotspot then you'd do something about it. -
That's a pretty unusual data representation. Double null-terminated strings are not uncommon on Windows at least. For what it is worth, you cannot call that null terminated, it is actually null separated. Personally, I would probably work with this sort of structure by converting to a string list and working on that internally. Then, at the interface between your code and the code that handles null separated data, convert it back to null separated. I use these methods to split and join: function Join(const Strings: array of string; Separator: Char): string; var Index: Integer; Len: Integer; Pos: Integer; begin if Length(Strings)=0 then begin Result := ''; Exit; end; Len := 0; for Index := 0 to High(Strings) do begin Inc(Len, Length(Strings[Index])); end; SetLength(Result, Len + High(Strings)); Pos := 1; for Index := 0 to High(Strings) do begin if Index>0 then begin Result[Pos] := Separator; Inc(Pos); end; Len := Length(Strings[Index]); Move(Pointer(Strings[Index])^, Result[Pos], Len*SizeOf(Char)); Inc(Pos, Len); end; end; function Split(const Str: string; Separator: Char): TArray<string>; var i, ItemIndex: Integer; len: Integer; SeparatorCount: Integer; Start: Integer; begin len := Length(Str); if len=0 then begin Result := nil; Exit; end; SeparatorCount := 0; for i := 1 to len do begin if Str[i]=Separator then begin Inc(SeparatorCount); end; end; SetLength(Result, SeparatorCount+1); ItemIndex := 0; Start := 1; for i := 1 to len do begin if Str[i]=Separator then begin Result[ItemIndex] := Copy(Str, Start, i-Start); Inc(ItemIndex); Start := i+1; end; end; Result[ItemIndex] := Copy(Str, Start, len-Start+1); end; Of course, you can work directly with the null separated strings. That will involve a function to find the index of the character at the start of the n-th item. Just loop through the string looking for the separator (null in your case). And then you can use Insert and Delete to modify the string.
-
Manage overloaded IfThen functions
David Heffernan replied to Mike Torrettinni's topic in General Help
That depends. I prefer to let the compiler choose whether or jot to inline. That seems to have better results than me doing it manually. -
Manage overloaded IfThen functions
David Heffernan replied to Mike Torrettinni's topic in General Help
No. For static class methods it makes no difference whether its a class or a record. -
Manage overloaded IfThen functions
David Heffernan replied to Mike Torrettinni's topic in General Help
Mine looks like this type Generic = class public class function IfThen<T>(Value: Boolean; const TrueResult, FalseResult: T): T; static; end; I don't think the name is that great, but my motivation was to use the same naming as the RTL. How I wish we could have generic functions outside of classes or records. Note that you should make this a static class method so that the class reference does not get passed.