Recent

Author Topic: TBits constructor  (Read 1686 times)

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
TBits constructor
« on: February 07, 2023, 02:54:44 am »
Is this a bug or an intention?

Class TBits, file classesh.inc, line 403:

Code: Pascal  [Select][+][-]
  1. constructor Create(TheSize : longint = 0); virtual;

I.e. whole class is carefully implemented with SizeInt (here it's Int64) and constructor is the only place with LongInt.

It can be easily workarounded:
Code: Pascal  [Select][+][-]
  1. var aBits: TBits;
  2.     N: Longword;
  3. begin
  4.   N:=4200000000;
  5.   aBits:=TBits.Create(0);
  6.   aBits.Size:=N;
IMO it is needless limit.
« Last Edit: February 07, 2023, 05:50:18 am by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TBits constructor
« Reply #1 on: February 07, 2023, 02:38:56 pm »
You need to have 2^63-1 bits in TBits?
(Yes, I understand it's inconsistent).

Bart

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: TBits constructor
« Reply #2 on: February 07, 2023, 03:02:31 pm »
additionally, what escapes me is the usage of a signed Integer for that.

I'm trying to wrap my mind around the question, in which scenario i could use a negative Size for something like this....
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: TBits constructor
« Reply #3 on: February 07, 2023, 03:29:17 pm »
I'm trying to wrap my mind around the question, in which scenario i could use a negative Size for something like this....
jump, jump, jump, raises hand, pick me !, pick me ! I know the answer to that question: NEVER !  :)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: TBits constructor
« Reply #4 on: February 07, 2023, 04:34:14 pm »
You need to have 2^63-1 bits in TBits?
(Yes, I understand it's inconsistent).

Bart

Hi!

For 2^64 bits you need

2.097.152 TeraByte

as RAM.

We continue the discussion about signed/unsigned parameter, when this machine is available.

Winni

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: TBits constructor
« Reply #5 on: February 07, 2023, 04:43:11 pm »
It's not that I need 2^64 of bits. It's that I need more than 2^31-1 of bits which is a poor 256MB.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: TBits constructor
« Reply #6 on: February 07, 2023, 06:46:29 pm »
Isn't it 2GB (2^31)
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: TBits constructor
« Reply #7 on: February 07, 2023, 06:50:42 pm »
Isn't it 2GB (2^31)
In bytes, yes. In bits, I do hope not  :)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: TBits constructor
« Reply #8 on: February 07, 2023, 07:04:16 pm »
True, I forgot we talk about bit  :-[
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: TBits constructor
« Reply #9 on: February 07, 2023, 09:06:06 pm »
additionally, what escapes me is the usage of a signed Integer for that.

Pascal essentially always favors signed types to unsigned ones: Length() returns SizeInt, Count returns LongInt and so on.

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: TBits constructor
« Reply #10 on: February 08, 2023, 07:27:34 am »
additionally, what escapes me is the usage of a signed Integer for that.

Pascal essentially always favors signed types to unsigned ones: Length() returns SizeInt, Count returns LongInt and so on.
But that’s „historical“, right?
Common sense says we’re wasting away a whole range.

Ah, well…
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: TBits constructor
« Reply #11 on: February 08, 2023, 08:16:21 am »
additionally, what escapes me is the usage of a signed Integer for that.

Pascal essentially always favors signed types to unsigned ones: Length() returns SizeInt, Count returns LongInt and so on.
But that’s „historical“, right?
Common sense says we’re wasting away a whole range.

Ah, well…

In the context of bits, we are wasting only one. You have 63 left (98,4%) :)

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: TBits constructor
« Reply #12 on: February 08, 2023, 08:35:46 am »
In the context of bits, we are wasting only one. You have 63 left (98,4%) :)
Yeah, in that particular case, but my comment was more in "general" (like Length, Count etc.)
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: TBits constructor
« Reply #13 on: February 08, 2023, 11:06:20 am »
When we are talking about 64 bits this does not matter that much, because Sizes are heavily linked to pointer differences and sizes greater than maxptr - minptr don't make much sense.
And I am not aware of any OS that uses the whole 64 bit address range, I think the limit for both windows and Linux today is 48 bit.
So the sign bit does not matter. And it can have some advantages as you can additional Information using the sign, e.g. errors

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: TBits constructor
« Reply #14 on: February 08, 2023, 09:29:44 pm »
additionally, what escapes me is the usage of a signed Integer for that.

Pascal essentially always favors signed types to unsigned ones: Length() returns SizeInt, Count returns LongInt and so on.
But that’s „historical“, right?

No, it's not historical, because the compiler by default calculates with signed integers and thus internally there is even a hidden 128-bit signed integer type, because it's required to correcty handle certain combinations of the 64-bit unsigned types.

And I am not aware of any OS that uses the whole 64 bit address range, I think the limit for both windows and Linux today is 48 bit.

That's also because the processors don't provide more (both x86_64 and ARM64 have MMU related registers that describe the size of the address space and right now both have 48-bit).

 

TinyPortal © 2005-2018