-
Content Count
3493 -
Joined
-
Last visited
-
Days Won
172
Everything posted by David Heffernan
-
BlockRead & BlockWrite - E2010 error
David Heffernan replied to Jud's topic in RTL and Delphi Object Pascal
This looks like a documentation error. It obviously doesn't make sense for the result to be passed back through a var param and a function return value. I think it should be like so: procedure BlockWrite(var F: File; const Buf; Count: Integer; var Written: Integer); overload; procedure BlockWrite(var F: File; const Buf; Count: Integer); overload; procedure BlockWrite(var F: File; const Buf; Count: Integer; var Written: Integer); overload; procedure BlockWrite(var F: File; const Buf; Count: Integer); overload; Your code gives the same error in Delphi 6, so I don't think anything has changed. Have a look at this section of Ray Lischner's book which says the same: https://www.oreilly.com/library/view/delphi-in-a/1565926595/re28.html -
BlockRead & BlockWrite - E2010 error
David Heffernan replied to Jud's topic in RTL and Delphi Object Pascal
Does the behaviour change then depending on whether or not IO errors are enabled? -
unit Bitset; interface uses SysUtils, Math; type TBitSet = record private FBitCount: Int64; FSets: array of set of 0..255; class function SetCount(BitCount: Int64): Int64; static; procedure MakeUnique; procedure GetSetIndexAndBitIndex(Bit: Int64; out SetIndex: Int64; out BitIndex: Integer); function GetIsEmpty: Boolean; procedure SetBitCount(Value: Int64); function GetSize: Int64; public class operator In(const Bit: Int64; const BitSet: TBitSet): Boolean; class operator Equal(const bs1, bs2: TBitSet): Boolean; class operator NotEqual(const bs1, bs2: TBitSet): Boolean; property BitCount: Int64 read FBitCount write SetBitCount; property Size: Int64 read GetSize; property IsEmpty: Boolean read GetIsEmpty; procedure Clear; procedure IncludeAll; procedure Include(const Bit: Int64); procedure Exclude(const Bit: Int64); end; implementation { TBitSet } procedure TBitSet.MakeUnique; begin // this is used to implement copy-on-write so that the type behaves like a value SetLength(FSets, Length(FSets)); end; procedure TBitSet.GetSetIndexAndBitIndex(Bit: Int64; out SetIndex: Int64; out BitIndex: Integer); begin Assert(InRange(Bit, 0, FBitCount-1)); SetIndex := Bit shr 8; // shr 8 = div 256 BitIndex := Bit and 255; // and 255 = mod 256 end; function TBitSet.GetIsEmpty: Boolean; var i: Int64; begin for i := 0 to High(FSets) do begin if FSets[i]<>[] then begin Result := False; Exit; end; end; Result := True; end; procedure TBitSet.SetBitCount(Value: Int64); var Bit, BitIndex: Integer; SetIndex: Int64; begin if (Value<>FBitCount) or not Assigned(FSets) then begin Assert(Value>=0); FBitCount := Value; SetLength(FSets, SetCount(Value)); if Value>0 then begin (* Ensure that unused bits are cleared, necessary give the CompareMem call in Equal. This also means that state does not persist when we decrease and then increase BitCount. For instance, consider this code: var bs: TBitSet; ... bs.BitCount := 2; bs.Include(1); bs.BitCount := 1; bs.BitCount := 2; Assert(not (1 in bs)); *) GetSetIndexAndBitIndex(Value - 1, SetIndex, BitIndex); for Bit := BitIndex + 1 to 255 do begin System.Exclude(FSets[SetIndex], Bit); end; end; end; end; function TBitSet.GetSize: Int64; begin Result := Length(FSets)*SizeOf(FSets[0]); end; class function TBitSet.SetCount(BitCount: Int64): Int64; begin Result := (BitCount + 255) shr 8; // shr 8 = div 256 end; class operator TBitSet.In(const Bit: Int64; const BitSet: TBitSet): Boolean; var SetIndex: Int64; BitIndex: Integer; begin BitSet.GetSetIndexAndBitIndex(Bit, SetIndex, BitIndex); Result := BitIndex in BitSet.FSets[SetIndex]; end; class operator TBitSet.Equal(const bs1, bs2: TBitSet): Boolean; begin Result := (bs1.FBitCount=bs2.FBitCount) and CompareMem(Pointer(bs1.FSets), Pointer(bs2.FSets), bs1.Size); end; class operator TBitSet.NotEqual(const bs1, bs2: TBitSet): Boolean; begin Result := not (bs1=bs2); end; procedure TBitSet.Clear; var i: Int64; begin MakeUnique; for i := 0 to High(FSets) do begin FSets[i] := []; end; end; procedure TBitSet.IncludeAll; var i: Int64; begin for i := 0 to BitCount-1 do begin Include(i); end; end; procedure TBitSet.Include(const Bit: Int64); var SetIndex: Int64; BitIndex: Integer; begin MakeUnique; GetSetIndexAndBitIndex(Bit, SetIndex, BitIndex); System.Include(FSets[SetIndex], BitIndex); end; procedure TBitSet.Exclude(const Bit: Int64); var SetIndex: Int64; BitIndex: Integer; begin MakeUnique; GetSetIndexAndBitIndex(Bit, SetIndex, BitIndex); System.Exclude(FSets[SetIndex], BitIndex); end; end. This is based on code of mine that has is limited to integer bit count. I've not tested it extended to Int64, but I'm sure anyone that wanted to use random code like this would test.
-
Why would you not expect to get a 32GB block when the available address space is 128TB?
-
What about the cost of moving data between gpu and main memory? Benefits of gpu are in highly parallel computation. Where is that in this scenario. Just saying GPU doesn't make something fast or efficient.
-
How could this be more efficient than a contiguous array?
-
BlockRead & BlockWrite - E2010 error
David Heffernan replied to Jud's topic in RTL and Delphi Object Pascal
Show complete but minimal code please -
No. You use a hashed collection. Like a dictionary, but one without a value, which is known as a set. But at 5% full then I don't think it will get you any benefit, because of the overhead of the hashed collection.
-
New Code Signing Certificate Recommendations
David Heffernan replied to James Steel's topic in General Help
Expect it to be discontinued at short notice when Google get bored of it -
How many such instances of this type do you need in memory at any time? And what's the expected number of bits that are set at any time? Do you really need to store all bits, both 0 and 1. Can't you just stor the 1s and infer the 0s from the fact that they aren't stored as 1s?
-
New Code Signing Certificate Recommendations
David Heffernan replied to James Steel's topic in General Help
Cloud HSM seems like a convenient solution. Seems expensive though. -
New Code Signing Certificate Recommendations
David Heffernan replied to James Steel's topic in General Help
They shipped a USB token which arrived next day. And for EV they just called me to confirm some details I provided on my order. Didn't seem very enhanced at all. -
You've got some memory corruption or broken interface handling code. It could be pretty much anywhere. You might get a better steer using FastMM with full debug options.
-
New Code Signing Certificate Recommendations
David Heffernan replied to James Steel's topic in General Help
I got an EV cert from globalsign recently and it only took a couple of days from start to finish. -
W1057 during D7 -> D11 conversion
David Heffernan replied to Bart Verbakel's topic in Algorithms, Data Structures and Class Design
OP doesn't want to run multiple machines. It's just one dev that wants to get rid of ancient Win7 laptop. My point is that you can just install D7 on Win 11. If that is helpful. -
W1057 during D7 -> D11 conversion
David Heffernan replied to Bart Verbakel's topic in Algorithms, Data Structures and Class Design
That's not what we are talking about. We are talking about running the ide on Windows 11. -
W1057 during D7 -> D11 conversion
David Heffernan replied to Bart Verbakel's topic in Algorithms, Data Structures and Class Design
Yeah. You just ignore those and generally install to a write able directory, or put a permissive acl on the installation directory. It's been that way for many windows versions too. -
W1057 during D7 -> D11 conversion
David Heffernan replied to Bart Verbakel's topic in Algorithms, Data Structures and Class Design
Really. I'm pretty sure you can run Delphi 7 on Win 11. -
Parallel for and CPU with Performance and Efficient cores
David Heffernan replied to Jud's topic in RTL and Delphi Object Pascal
They tend not to break things. Also, ignoring affinities would utterly break aot of software, and break some software that set affinities correctly. So, no, this isn't a risk. -
Parallel for and CPU with Performance and Efficient cores
David Heffernan replied to Jud's topic in RTL and Delphi Object Pascal
Seems unlikely that MS would break its system because some people write crap programs. -
Handling Python indented blocks with ExecString()
David Heffernan replied to RSG's topic in Python4Delphi
Is it really the best way to go delphi to python to octave? Must be possible to go straight to octave but far better to use python rather than octave/matlab. -
Handling Python indented blocks with ExecString()
David Heffernan replied to RSG's topic in Python4Delphi
Not much use for a REPL -
My TStringList custom SORTing, trying to mimic Windows Explorer way
David Heffernan replied to programmerdelphi2k's topic in Algorithms, Data Structures and Class Design
It would be cool to look at the Wine implementation of StrCmpLogicalW and port that to Pascal once and for all for a cross platform implementation. https://gitlab.winehq.org/wine/wine/-/blob/master/dlls/kernelbase/string.c#L1298 Looks kinda simple really- 5 replies
-
- tstinglist
- sort
-
(and 2 more)
Tagged with:
-
W1057 during D7 -> D11 conversion
David Heffernan replied to Bart Verbakel's topic in Algorithms, Data Structures and Class Design
Blitting a record to a binary file makes it more tricky. Nobody but you can really know what to do. Perhaps you just carry on and suppress the warnings after localising them. But why go to Delphi 11 then? If you carry on as you are you can't do Unicode. Maybe you don't need international language support. Maybe you don't mind having pre determined max text lengths. But if you want to go beyond these limitations it's going need some thought and design. -
W1057 during D7 -> D11 conversion
David Heffernan replied to Bart Verbakel's topic in Algorithms, Data Structures and Class Design
No. Its perfectly possible to save any string type to a file.