Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clarification using _MEM
#4
Try this out and see if it doesn't help you figure out what's going on:

Code: (Select All)
Dim m As _MEM
Dim a(100) As Long '404 byte
m = _Mem(a()) 'mem pointed at a()

For i = 0 To 10
Print i, m.SIZE 'note that this never changes
Next
Sleep

For i = 0 To 10
m = _Mem(a(i)) 'but now notice what we see here
Print i, m.SIZE
Next


the SIZE is basically how much reserved space is available at that point where you're referencing it.

Now, if m is always pointing to offset 0, then you will always have the full size returned to you.

But now, if you notice what happens when I moved the offset to various positions via _MEM(a(i)), you'll see that value changes.

Honestly, I don't know *why* I'd ever want to get the mem.SIZE from element 4 to the end, but that's how it works. Seems like all I'd ever work with would either be mem.ELEMENTSIZE for a particular element, or else I'd just calculate that figure myself.

To tell the truth, I don't think I'd ever even noticed that it behaves the way it actually does here. LOL -- It's not something I've ever made use of, that's for certain! Wink

(01-23-2024, 07:12 PM)DSMan195276 Wrote:
(01-23-2024, 06:52 PM)TerryRitchie Wrote: However MemBlock.SIZE never changes in value as I navigate through the memory block. What does the wiki mean by stating " size of block remaining at offset(changes with position) "?

Any help would be appreciated. I'm delving into the MEM statements and making great progress but this has me baffled.
The comment on the definition is a little odd, maybe there's a situation where you can get a new _MEM that is offset from the original but I don't know of it.

That said I wouldn't read into it too much, `_MEM` works like any regular UDT except that the it's read-only. The logic `Offset = MemBlock.OFFSET` and `Offset = Offset + 4` only modifies the `Offset` variable you created, it has no impact on the original `_MEM` variable.

With arrays.   Point to an element in an array and the SIZE changes depending upon that element.  Seems odd to me, but that's just the way it's always been.  /shrug   See my demo above.  Wink
Reply


Messages In This Thread
Clarification using _MEM - by TerryRitchie - 01-23-2024, 06:52 PM
RE: Clarification using _MEM - by SpriggsySpriggs - 01-23-2024, 07:03 PM
RE: Clarification using _MEM - by DSMan195276 - 01-23-2024, 07:12 PM
RE: Clarification using _MEM - by SMcNeill - 01-23-2024, 07:21 PM
RE: Clarification using _MEM - by DSMan195276 - 01-23-2024, 07:41 PM
RE: Clarification using _MEM - by TerryRitchie - 01-23-2024, 07:45 PM



Users browsing this thread: 1 Guest(s)