Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
B4G Library by v1ctor question
#1
Hello, I'm new to this forum, and I think that you can help me, because I read a lot of members posts, and you all are great in helping and discussing smth.
I have a problem, I'm not new to QB, I'm working on some project, but I need more memory, because there is a lot of information which has to written in to memory, I don't want to use hdd for temp files of something. So it is not enought memory which gives me original qb in pure dos mode. So I tried to use B4G library by v1ctor. Everything is fine, it enters pmode... but what next? Documentation is not very detailed as for me Sad. I just want to make for examle 10 variables for about 256kb size and to put here a string, and then to read this string. How to do this? I need help... So, maybe somebody could help me? I would be very thankful...
Sorry for my English, I'm from Lithuania... :oops:
Reply
#2
Well, the peekpoke.bas example shows how to do all kinds of write/read accesses to extended memory (remember, it's not XMS), including strings.

For what you want to do, it would be like:

Code:
defint a-z
'$include: 'b4g.bi'

const STRINGS%    = 10000
const STRINGLEN& = 512
const BLKSIZE&     = STRINGS * STRINGLEN
const CACHESIZE% = STRINGLEN*20

  '' try switch to 32-bit protected mode
  if (b4ginit > 0) then
     end
  end if

  '' alloc a block of extended memory
  dim xblk as long
  xblk = xmalloc(BLKSIZE)
  if (xblk = 0) then
     end
  end if

  '' fill block with spaces
  xmfill xblk, BLKSIZE, 32

Now you can access the block directly using the xmpoke### and xmpeek### routines, but switching to pmode and returning to rmode can take a lot of time, it would be better to use the mapped (cached) peek and poke routines (xmappoke### an xmappeek###), for that you need first to create a map and point it to the block allocated above:

Code:
dim map as long
  map = xmapmake(CACHESIZE)
  if (map = 0) then
     end
  end if

  xmap xblk, BLKSIZE, map

Now to write/read the strings:

Code:
for i = 0 to STRINGS-1
     xmappokestr map, i * STRINGLEN, "String:" + ltrim$( str$( i ) )
  next i

  for i = 0 to STRINGS-1
     print rtrim$( xmappeekstr(map, i * STRINGLEN, STRINGLEN) );
  next i


Don't forget to free the block allocated and to close the library:

Code:
xmfree xblk
  b4gdone

I hope i was clear enough ;).. long time i don't use that lib.. like.. 4 years or such, ugh.. any doubt..
Reply
#3
Thank you very much! Now I understand everything Wink
Thx :bounce:
Reply
#4
no prob ;)

i'm glad someone is at least trying B4G, since i released the lib, nobody really used it in these 4 years ;)
Reply
#5
Hehem I use it :wink: And Z!re is even writing a fakeOS (Novix) using it
url]http://fbide.sourceforge.net/[/url]
Reply
#6
Really? cool, how are you going to use it, to store scripts?

I had an project to write a pmode gfx lib with b4g, to get free from banks and segments with bitmaps/DCs, but then Win NT/2k/XP appeared, non supporting Linear Frame Buffer on VBE 2+ video-cards, too bad..

Btw, boostqb could be used when executing the byte-code scripts. Creating a jump table, you could just do like:

Code:
do
  opcode = asc( scriptbuffer(ip) )
  ip = ip + 1
  call procedure( ip, jumpTB(opcode) )
loop until( (integerRet = -1) or (ip = endbuffer) )

And have a sub-routine to execute each instruction, like

Code:
function add%( ip as integer ) static

  reg = asc( scriptbuffer(ip+0) )
  val  = cvi( scriptbuffer(ip+1) )
  ip = ip + 1 + 2

  regTB(reg) = regTB(reg) + val
  
  add = 0 'still going
end sub

Would be waaay faster than using an huge IF or SELECT statement..
Reply
#7
WOW I have no words. It's exactly what I need. Yeah I want to use it to store running script and also variables. I have to think about it and try to understand what you mean :oops: though

Okay Tnx
url]http://fbide.sourceforge.net/[/url]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)