I do work with it.
And you can get even 10mb if you want. However working with it is a bit different then with qb's. You can read and write into that memory: bytes(not in qb, but is equal to one byte STRING*1-is the closest), integers, longs, singles, doubles and strings -oh also udt(user defined types) here's small example:
before anything you need to start the basic with b4g:
Code: Select all
qb /l b4g.qlb 'for qb4.5
qbx /l b4gx.qlb 'for qbx 7.1
qbv /l b4gv.qlb 'for vbdos
and then add '$include: 'b4g.bi' in the beginning of your code.
first let's allocate some memory:
all identifiers must be of long type!
Code: Select all
Size&=&h100000 'that's 1MB 'the size we're gonna use.
buffer&=&h10000 'that's 64k buffer for mapped memory (is a lot faster)
xblk& = xmalloc(Size&) 'allocate memory
Map& = xmapmake(Buffer&) 'make a buffer.
xmap xblk&, Memory&, Map& 'create a memory map.
Before to proceed we need to check if initalisation was successful:
Code: Select all
IF (xblk& = 0) OR (Map& = 0) THEN
PRINT "Not enough memory!"
CLOSE
EXIT FUNCTION
END IF
Now that this is done we can read/write data in it.
to read a byte:
NB! you need to know the location from where to read that byte. Also location is LONG type as well to write byte to the memory is almost same, but
the same way works
Code: Select all
iInt% = xMapPeekI(xMap, offset&) 'integer
iLong& = xMapPeekL(xMap, offset&) 'long
iSingle! = xMapPeekS(xMap, offset&) 'Single
iDouble# = xMapPeekD(xMap, offset&) 'double
and their opposites:
Code: Select all
xPokeI(xMap, offset&,iInt%) 'integer
xMapPokeL(xMap, offset&,iLong&) 'long
xMapPokeS(xMap, offset&,iSingle!) 'Single
xMapPokeD(xMap, offset&,iDouble#) 'double
Strings are a bit different, becouse you also need to know the lenght of teh string. But to write a string, you can just go as before:
Code: Select all
xMapPokeStr(xMap, offset&, text$)
, but to read string back you need to specify the lenght(it is useful to get the size of the string before you push it to the memory, a=len(text$), so to read:
Code: Select all
Text$=xMapPeekStr$(xMap, Offset&, Stringlenght%)
Using UDT's: Once you have one you can also push it to the memory and read it back later, of course memory locations is smth you need always to know, so:
Code: Select all
TYPE blabla
i as integer
x as string*10
y as long
end type
dim udt as blabla
xMapPokeT(xMap, Offset&, udt, len(udt)) 'pushes content of udt to memory.
len(udt) gives the size in bytes of the UDT. now to read it back:
Code: Select all
xMapPeekT(xMap, Offset&, udt, len(udt))
Note that xMapPeekT is NOT a function. also the name udt, must be predefined with dim statament. To test, if it works you can for example null it's values before returning it from memory.
Note then when exiting you need to deinit it
Anyway this is short introduction to b4g, it's not as easy as qb's memory handling is, but it's powerful. In one memory container you can store anything you like, even write as integers, and read as string from the same location -that can be fun. There's no restriction's about what you read/write as long as you are inside the memory limit.