1

I use Python4Delphi in D7. I want to pass object address as "handle" to Py part. E.g.
h:= Integer(Pointer(Memo1));. I also want to have special handle values, which mean some specials objects, e.g. -1 means "current memo", -2 means "next memo".

How can I choose such few (I need 5) constants, which won't conflict with object adresses? E.g.

  • -1 - can it be address of some TMemo (of other TObject)?
  • -2 - can it be address of some TMemo?
  • what else constants can I take which cannot be TMemo addresses?
Prog1020
  • 4,530
  • 8
  • 31
  • 65
  • 2
    In Win32, the first 64KB of address space is permanently invalid. – Free Consulting Feb 06 '14 at 22:22
  • [David's answer](http://stackoverflow.com/a/21615291/224704) is the way to go. In addition I'd like to point out: Negative numbers _could_ work as sentinels if the app isn't compiled with LARGE_ADDRESS_AWARE enabled. **Howver**, I strongly advise **against** this approach, because it effectively prevents you from using that option. – Disillusioned Feb 07 '14 at 10:13

1 Answers1

5

Certainly on Windows, you can use low addresses for this purpose. You need five sentinel values? Use 1 to 5. Those values are never valid addresses in user space.

Of course, if you are prepared to allocate the values at runtime, you can reserve some addresses for yourself with a simple call to GetMem. Again, you need five addresses, call GetMem(5) and you are done.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490