MemoryBlock vs Ptr Difference

| | Comments (0)

I ran into a difference between MemoryBlock and Ptr today, so I figured it'd make for a nice blog posting.

dim w, w2 as WString
dim mb as MemoryBlock = somePtr
w = mb.WString( 0 )
w2 = somePtr.WString( 0 )

You'd think that w and w2 would be the same WString, but alas, they are not. Ptr.WString takes the memory location at the offset given, dereferences it, and starts grabbing UTF-16 data until it hits a null character. MemoryBlock.WString uses the memory block's start adress plus the offset given and starts grabbing UTF-16 data until it hits a null character. The main difference is that Ptr treats WString as a pointer to UTF-16 data, and MemoryBlock treats WString as an offset to the UTF-16 data (no dereferencing needed).

Watch out for that one!

Leave a comment

Disclaimer

I'm currently an employee of REAL Software. My blog is mine. The opinions represented in this blog are mine as well and may not represent my employer's opinions. All original material is copyrighted and property of the author.

REALbasic® is a registered trademark of REAL Software, Inc. REAL SQL Server™ and Lingua™ are pending trademarks of REAL Software, Inc. All rights reserved.