Memory functions similar to file functions

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Memory functions similar to file functions

Post by localmotion34 »

Whenever working with memory buffers, i always find myself looking for a better algorithm to determine where i am inside the buffer, especially when decoding image scanlines or reading compressed data. i did notice however, that when working with files, i always know i am at the file position right after where i just read. the file operations keep the position constant until the next operation, or the file is closed.

How about a memory function like ReadMemory(Buffer), which after reading a long/word/byte, keeps the memory position right after where you just read, similar to the file functions.

so:

ReadMemory(buffer)
long=RMreadlong(buffer)
debug memloc(buffer)
word=RMreadword(buffer)
debug memloc(buffer)
MemorySeek(buffer,somewhere)
Debug EOM(buffer) ; "End of Memory"
closememory(buffer)

This would enormously simplify dealing with large memory blocks, and would avoid having to do:

for d=0 to something
long=peekl(buffer, (x*y*d)+ d)
next

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw