Recent

Author Topic: Hashing pointers by using their memory address as keys?  (Read 1461 times)

cdbc

  • Hero Member
  • *****
  • Posts: 2561
    • http://www.cdbc.dk
Re: Hashing pointers by using their memory address as keys?
« Reply #15 on: December 14, 2025, 01:34:07 am »
Hi
PtrInt/PtrUInt are aliases for the 'register-sized' (or pointer-sized) integer for the platform...
16 bit = 2 byte integers
32 bit = 4 byte integers
64 bit = 8 byte integers
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

jamie

  • Hero Member
  • *****
  • Posts: 7490
Re: Hashing pointers by using their memory address as keys?
« Reply #16 on: December 14, 2025, 01:53:37 am »
The more I look at this the more I get the feeling that maybe a TMultiMap is what the game is here.

I wrote one of those for an app subclassing at TFPGMAP with a TFPGList which came out nicely.

It allows to add multiple items under a single Key name.

This sort of is like a Hash list I guess.

Jamie

The only true wisdom is knowing you know nothing

440bx

  • Hero Member
  • *****
  • Posts: 6020
Re: Hashing pointers by using their memory address as keys?
« Reply #17 on: December 14, 2025, 03:16:33 am »
general comment:

since the size of a pointer changes with the bitness, a pointer should _never_ be typecasted to a fixed size type since that will not be correct in more than one bitness.

a pointer should be typecast to one of the types whose size are bitness dependent (just like pointers), the most common ones are ptrint and ptruint.

using "absolute" isn't safer than directly typecasting, it just stops the compiler from emitting warnings.

Personally, I much prefer using "absolute" to overlay a variable of type ptruint on a pointer than typecasting the pointer.  This because, it can prevent the compiler from emitting a lot of warnings that basically end up being "noise" that get in the way of noticing other important warnings.

HTH.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018