Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Bouncing around Memblocks

Author
Message
CumQuaT
AGK Master
14
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 18th Apr 2016 12:48
Hi all,

Say I was to use MAKE MEMBLOCK FROM FILE to suck in the contents of a fairly small text file, store it, and then bounce around it for a bit.

What do I mean by "bounce around"? I'd like to be able to read strings out of it as if I were using the READ STRING command with a normal OPEN TO READ operation, however, the difference is, I'd like to be able to move the read cursor back to the start of the memblock again.

So basically, I want to start reading strings out of the memblock from the beginning to the end, but at any point jump back to the start again and repeat the process.

Does anyone have any ideas on how I would do this?
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 18th Apr 2016 17:18 Edited at: 18th Apr 2016 17:19
Write some pre processing code that step through the source text file and work out the offsets of the strings in the raw output data. So the output data has a header containing the number of strings say, followed by a list of (32bit) offsets to the first character of the string in the data heap. Depending upon the language you could store the size of the string at this offset followed by the raw characters, or store it null terminated.. Bellow i've assume they'd be null terminated..


Here's how such a structure might when it cotains 2 strings.


When converting the text data you can have it removed duplicates for example. Or token the text and store them as list of tokens, but that's a bit more stuffing around with the data up front. You ould do the string operations in memblocks also, as DBpro string oeprations aren't that quick.

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
CumQuaT
AGK Master
14
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 20th Apr 2016 00:32
Thanks, Kevin!

Login to post a reply

Server time is: 2024-05-19 07:54:38
Your offset time is: 2024-05-19 07:54:38