Re: detecting if an atom is a pointer
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Nov 16, 2006
- 570 views
On Wed, 15 Nov 2006 15:45:06 -0800, Chris Bensler <guest at RapidEuphoria.com> wrote: >In my testing it appears that the pointers never use all the high >bits. Is this because Eu's heaps? or OS heaps? Would it be safe to use >those bits to detect identifiers? The windows api GlobalAlloc is documented somewhere as always returning 8-byte aligned addresses, but occasionally it does not. On a 32-bit machine, all native allocation methods will be 32-bit aligned. However:
atom ptr ptr = allocate(10) ?ptr poke(ptr,"0123456789") while peek(ptr)<'3' do ptr+=1 end while ?ptr
clearly results in a non-4-byte-aligned pointer, and likewise any pointer returned from a c function is probably 4-byte-aligned but in no way guaranteed to be. GetLogicalDriveStrings springs to mind as a c/winapi function which packs strings back-to-back, leading to code like the above. So the answer is that you probably could get something working by mangling/mapping C_INT etc to always have one or both of the two least significant bits set, but one day it will break. I also remember once assuming that allocate (or api) won't return memory addresses below something like #00100000 because that is where the OS or something similar lives on win98. Of course it went belly up the first time anyone ran it on XP. My advice: pass an extra boolean flag to indicate what it is. Regards, Pete