Clarification using _MEM - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Clarification using _MEM (/showthread.php?tid=2400) |
Clarification using _MEM - TerryRitchie - 01-23-2024 In the wiki under _MEM is this: TYPE memory_type OFFSET AS _OFFSET 'start location of block(changes with byte position) SIZE AS _OFFSET 'size of block remaining at offset(changes with position) TYPE AS _OFFSET 'type description of variable used(never changes) ELEMENTSIZE AS _OFFSET 'byte size of values inside the block(never changes) IMAGE AS LONG 'the image handle used when _MEMIMAGE(handle) is used SOUND AS LONG 'the sound handle used when _MEMSOUND(handle) is used END TYPE I'm interested in using SIZE to determine how much of the memory block is left to process, if that's possible. I'm getting an image's memory location: MemBlock = _MEMIMAGE(ImageHandle) Then getting its offset: Offset = MemBlock.OFFSET Then iterating through the memory block: DO _MEMGET MemBlock, Offset, Pixel 'other code here _MEMPUT Memblock, Offset, Pixel Offset = Offset + 4 LOOP UNTIL MemBlock.SIZE = 4 ' (or perhaps 0?) 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. RE: Clarification using _MEM - SpriggsySpriggs - 01-23-2024 The OFFSET is the location of the MEM block. The SIZE is how big the MEM block is at that OFFSET. Think of OFFSET doing the same thing as _OFFSET(yourMemBlock). You could take your current position and subtract it from the size to see how much you have left. If the offset is 62349, for instance, and the size is 32, you can know that 62381 should be the end of the MEM block. I'm probably not explaining this coherently, but I hope it helps a bit. I don't think size is supposed to be marked as something that changes. That might be a typo. RE: Clarification using _MEM - DSMan195276 - 01-23-2024 (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) "?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. RE: Clarification using _MEM - SMcNeill - 01-23-2024 Try this out and see if it doesn't help you figure out what's going on: Code: (Select All)
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! (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) "?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. 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. RE: Clarification using _MEM - DSMan195276 - 01-23-2024 (01-23-2024, 07:21 PM)SMcNeill Wrote: 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.I suppose I was picturing the `_OFFSET` and `SIZE` in the existing `_MEM` being changed (since the comment says "changes"). Your code example doesn't change the original `_MEM` instance, it's creating new ones for each `_Mem()` call that you will then have to then `_MemFree`. RE: Clarification using _MEM - TerryRitchie - 01-23-2024 Ok, thank for the replies guys, that does make sense. I wrote a subroutine the makes a negative image (inspired by another recent post) and wanted to see how small and fast I could make it. Here is what I have: Code: (Select All) ' _______________________________________________________________________________________________________ |