Posted: 15th Mar 2021 14:09
I am writing code to allow the user to create an array from a memblock, bank or alloc memory. This works also with strings. As you probably know the DBPro command "Make Array From Memblock" doesn't work with strings. DBPro stores DWORD s and not the actual text data. So the use of pointers are required here and reading the content of the address pointer.
Now works with alloc, Memblocks and Banks (Matrix1Utils by IanM).

[version 0.14 both UDT to UDT strings. I was going to do the offsets in this code but changed my mind. Will be in v0.15. As you can see in this code iptr and *iptr are 2 differenct values. iptr is the arryay ptr to an item in the array and *iptr is the actual address ptr which points to the text data. This does away with using t$ and specifying the .txt, you can just go to the specific offset item.]
+ Code Snippet
Rem Project: memory_to_array (including strings)
Rem Created: Friday, June 11, 2021

Rem ***** Main Source File *****
Rem ***** draft version 0.14 - with UDT -> UDT (offsets) *****
backdrop off
sync on : sync rate 30 : sync
type myUDT
	txt as string
endtype

`dim dwary(2) as dword // items=3 0-2  (notice not used "as string" we are storing the dword address that points the the actual text in memory)
dim dwary(2) as myUDT // items=3 0-2  (notice not used "as string" we are storing the dword address that points the the actual text in memory)
`dim strary(2) as string // items=3 0-2
dim strary(2) as myUDT // items=3 0-2
strptr as dword
strptr=get arrayptr(strary())
dwptr as dword
dwptr = get arrayptr(dwary())
dwtype = get arrayptr type(dwptr)
`print "dwptr: ";dwptr;", dwtype: ";dwtype 
rem below for memblock memory
memid=find free memblock()
memptr=MakeMemoryFromFile(1,memid,"input.txt")
memsz=get memblock size(memid)

rem below for bank memory
`memid=find free bank()
`memptr=MakeMemoryFromFile(2,memid,"input.txt")

rem below for ALLOC memory- use 0 for memid as n/a
`memptr=MakeMemoryFromFile(3,0,"input.txt")

rem ok for both ALLOC and BANK memory - do not use for memblocks
`memsz=memory size(memptr)

REM code below is for strings

if memptr > 0
	MakeArrayFromMemory(memptr,memsz,dwptr,2)
	cnt=get arrayptr count(dwptr)
	for i=0 to cnt 
		iptr=get arrayptr item ptr(dwptr,i)
		sptr=get arrayptr item ptr(strptr,i)
		`t$ = peek string(*iptr)
		`strary(i)= t$
		`print strary(i)
		poke dword sptr,*iptr
		print peek string(*sptr)
	next i
endif

sync
wait key
`undim dwary()
undim strary()
undim arrayptr dwptr

`delete memory - as appropriate
if memblock exist(memid)=1 then delete memblock memid
`if bank exist(memid)=1 then delete bank memid 
`free memptr
end

function MakeMemoryFromFile(mtype,memid,src$)
	// mtype: 1=memblock 2=bank 3=alloc
	if file exist(src$)=0 or mtype<1 or mtype>3
		exitfunction 0 
	endif

	if mtype=1
		mid=memid
		fid=find free file()
		open to read fid,src$
		make memblock from file mid,fid
		close file fid
		`fix code
		if memblock exist(mid)=0
			exitfunction 0 
		endif
		msz = Get Memblock Size(mid)
		tmid = Find Free Memblock()
		
		for b=0 to msz-1
			if memblock byte(mid, b) = 13 or memblock byte(mid, b) = 10
				write memblock byte mid,b,0
			endif  
		next b
		
		make memblock tmid,msz
		for b=0 to msz-1
			write memblock byte tmid,b,0
		next b
	
		tb=0
		for b=0 to msz-1
			byt=Memblock Byte(mid,b)
			if byt <> 0
				write memblock byte tmid,tb,byt
				inc tb
			else
				inc b
				inc tb
			endif
		next b
		
		if memblock exist(mid) then delete memblock mid
		make memblock mid,msz
		copy memblock tmid,mid,0,0,msz
		if memblock exist(tmid) then delete memblock tmid
		newmptr=get memblock ptr(mid)
	endif
	
	if mtype=2
		mid=memid
		make bank from file mid,src$
		`fix code
		if bank exist(mid)=0
			exitfunction 0 
		endif
		msz = Get Bank Size(mid)
		tmid = Find Free Bank()
		
		for b=0 to msz-1
			if bank byte(mid, b) = 13 or bank byte(mid, b) = 10
				write bank byte mid,b,0
			endif  
		next b
	
		make bank tmid,msz
		for b=0 to msz-1
			write bank byte tmid,b,0
		next b
	
		tb=0
		for b=0 to msz-1
			byt=Bank Byte(mid,b)
			if byt <> 0
				write bank byte tmid,tb,byt
				inc tb
			else
				inc b
				inc tb
			endif
		next b
		
		if bank exist(mid) then delete bank mid
		make bank mid,msz
		copy bank tmid,0,msz,mid,0
		if bank exist(mid) then delete bank tmid
		newmptr=get bank ptr(mid)		
	endif
	
	if mtype=3
		fsz=file size(src$)
		mptr=alloc Zeroed(fsz)
		fid=find free file()
		open to read fid,src$
		for addr=mptr to mptr+fsz-1
			read byte fid,byt
			poke byte addr,byt
		next addr	
		close file fid
		
		`fix memory code integrated
		msz = Memory Size(mptr)
		if msz=0
			exitfunction 0 
		endif
		
		for addr=mptr to mptr+msz-1
			if peek byte(addr) = 13 or peek byte(addr) = 10
				poke byte addr,0
			endif  
		next addr
	
		tmptr = alloc zeroed(msz)
		tb=0
		for addr=mptr to mptr+msz-1
			byt=peek byte(addr)
			if byt <> 0
				poke byte tmptr+tb,byt
				inc tb
			else
				inc addr
				inc tb
			endif
		next addr
		
		free mptr
		newmptr=alloc zeroed(msz)
		` copy mem to mem
		bpos=0
		for addr=tmptr to tmptr+msz-1
			byt=peek byte(addr)
			poke byte newmptr+bpos,byt
			inc bpos
		next addr
		free tmptr		
	endif 			
endfunction newmptr

function MakeArrayFromMemory(mptr,msz,aryptr,vtype)
	// vtype : no value type/integer=0, 1=float, 2=string, 3=boolean, 
	//         4=byte, 5=word, 6=dword, 7=double float, 8=double integer
	stpos as dword
	if vtype <0 or vtype >8 
		message "type is invalid, parse 1-8 only."
		exitfunction
	endif
	
	select vtype
		case 0
			loopstep=4
		endcase

		case 1
			loopstep=4
		endcase

		case 2
			loopstep=1
		endcase

		case 3
			loopstep=1
		endcase

		case 4
			loopstep=1
		endcase
		
		case 5
			loopstep=2
		endcase

		case 6
			loopstep=4
		endcase
		
		case 7
			loopstep=8
		endcase
		
		case 8
			loopstep=8
		endcase

	endselect
	
	index=0
	stpos=mptr
	bpos=-1
	for addr = mptr to (mptr+msz)-loopstep step loopstep
		iptr = aryptr+get arrayptr item ptr(aryptr,index)
		select vtype
			case 0 
				value=peek integer(addr)
				poke integer iptr,value
			endcase

			case 1
				value#=peek float(addr)
				poke float iptr,value#
			endcase

			case 2
				inc bpos
				b=peek byte(addr)
				b1=peek byte(addr+1)
				if (addr-mptr)=msz-1 then exit
				if b>=32 and b<=127 and b1 = 0
					inc strcount
					if strcount =1
						iptr=get arrayptr item ptr(aryptr,strcount-1)
						poke dword iptr,stpos
						nbpos=bpos+1
					else
						if strcount > 1
							iptr=get arrayptr item ptr(aryptr,strcount-1)
							poke dword iptr,stpos+nbpos+1
							nbpos=bpos+1
						endif
					endif
				endif
			endcase

			case 3 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
			
			case 4 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
		
			case 5 
				value=peek word(addr)
				poke word iptr,value
			endcase

			case 6 
				value=peek dword(addr)
				poke dword iptr,value
			endcase
	
			case 7 
				value=peek double float(addr)
				poke double float iptr,value
			endcase
	
			case 8 
				value=peek double integer(addr)
				poke double integer iptr,value
			endcase
		endselect 		
		inc index
	next addr
endfunction


[version 0.13-both UDT and non UDT strings. At the moment I have just specified 1 variable in the UDT type definition. For more than 1 variable, we need to use offsets which is straightforward. Will add that in next code version]

+ Code Snippet
Rem Project: memory_to_array (including strings)
Rem Created: Thursday, June 10, 2021

Rem ***** Main Source File *****
Rem ***** draft version 0.13 - with UDT *****
backdrop off
sync on : sync rate 30 : sync
type myUDT
	txt as string
endtype

`dim dwary(2) as dword // items=3 0-2  (notice not used "as string" we are storing the dword address that points the the actual text in memory)
dim dwary(2) as myUDT // items=3 0-2  (notice not used "as string" we are storing the dword address that points the the actual text in memory)
dim strary(2) as string // items=3 0-2

dwptr as dword
dwptr = get arrayptr(dwary())
dwtype = get arrayptr type(dwptr)
`print "dwptr: ";dwptr;", dwtype: ";dwtype 
rem below for memblock memory
memid=find free memblock()
memptr=MakeMemoryFromFile(1,memid,"input.txt")
memsz=get memblock size(memid)

rem below for bank memory
`memid=find free bank()
`memptr=MakeMemoryFromFile(2,memid,"input.txt")

rem below for ALLOC memory- use 0 for memid as n/a
`memptr=MakeMemoryFromFile(3,0,"input.txt")

rem ok for both ALLOC and BANK memory - do not use for memblocks
`memsz=memory size(memptr)

REM code below is for strings

if memptr > 0
	MakeArrayFromMemory(memptr,memsz,dwptr,2)
	cnt=get arrayptr count(dwptr)
	for i=0 to cnt 
		iptr=get arrayptr item ptr(dwptr,i)
		t$ = peek string(*iptr)
		strary(i)= t$
		print strary(i)
	next i
endif

sync
wait key
`undim dwary()
undim strary()
undim arrayptr dwptr

`delete memory - as appropriate
if memblock exist(memid)=1 then delete memblock memid
`if bank exist(memid)=1 then delete bank memid 
`free memptr
end

function MakeMemoryFromFile(mtype,memid,src$)
	// mtype: 1=memblock 2=bank 3=alloc
	if file exist(src$)=0 or mtype<1 or mtype>3
		exitfunction 0 
	endif

	if mtype=1
		mid=memid
		fid=find free file()
		open to read fid,src$
		make memblock from file mid,fid
		close file fid
		`fix code
		if memblock exist(mid)=0
			exitfunction 0 
		endif
		msz = Get Memblock Size(mid)
		tmid = Find Free Memblock()
		
		for b=0 to msz-1
			if memblock byte(mid, b) = 13 or memblock byte(mid, b) = 10
				write memblock byte mid,b,0
			endif  
		next b
		
		make memblock tmid,msz
		for b=0 to msz-1
			write memblock byte tmid,b,0
		next b
	
		tb=0
		for b=0 to msz-1
			byt=Memblock Byte(mid,b)
			if byt <> 0
				write memblock byte tmid,tb,byt
				inc tb
			else
				inc b
				inc tb
			endif
		next b
		
		if memblock exist(mid) then delete memblock mid
		make memblock mid,msz
		copy memblock tmid,mid,0,0,msz
		if memblock exist(tmid) then delete memblock tmid
		newmptr=get memblock ptr(mid)
	endif
	
	if mtype=2
		mid=memid
		make bank from file mid,src$
		`fix code
		if bank exist(mid)=0
			exitfunction 0 
		endif
		msz = Get Bank Size(mid)
		tmid = Find Free Bank()
		
		for b=0 to msz-1
			if bank byte(mid, b) = 13 or bank byte(mid, b) = 10
				write bank byte mid,b,0
			endif  
		next b
	
		make bank tmid,msz
		for b=0 to msz-1
			write bank byte tmid,b,0
		next b
	
		tb=0
		for b=0 to msz-1
			byt=Bank Byte(mid,b)
			if byt <> 0
				write bank byte tmid,tb,byt
				inc tb
			else
				inc b
				inc tb
			endif
		next b
		
		if bank exist(mid) then delete bank mid
		make bank mid,msz
		copy bank tmid,0,msz,mid,0
		if bank exist(mid) then delete bank tmid
		newmptr=get bank ptr(mid)		
	endif
	
	if mtype=3
		fsz=file size(src$)
		mptr=alloc Zeroed(fsz)
		fid=find free file()
		open to read fid,src$
		for addr=mptr to mptr+fsz-1
			read byte fid,byt
			poke byte addr,byt
		next addr	
		close file fid
		
		`fix memory code integrated
		msz = Memory Size(mptr)
		if msz=0
			exitfunction 0 
		endif
		
		for addr=mptr to mptr+msz-1
			if peek byte(addr) = 13 or peek byte(addr) = 10
				poke byte addr,0
			endif  
		next addr
	
		tmptr = alloc zeroed(msz)
		tb=0
		for addr=mptr to mptr+msz-1
			byt=peek byte(addr)
			if byt <> 0
				poke byte tmptr+tb,byt
				inc tb
			else
				inc addr
				inc tb
			endif
		next addr
		
		free mptr
		newmptr=alloc zeroed(msz)
		` copy mem to mem
		bpos=0
		for addr=tmptr to tmptr+msz-1
			byt=peek byte(addr)
			poke byte newmptr+bpos,byt
			inc bpos
		next addr
		free tmptr		
	endif 			
endfunction newmptr

function MakeArrayFromMemory(mptr,msz,aryptr,vtype)
	// vtype : no value type/integer=0, 1=float, 2=string, 3=boolean, 
	//         4=byte, 5=word, 6=dword, 7=double float, 8=double integer
	stpos as dword
	if vtype <0 or vtype >8 
		message "type is invalid, parse 1-8 only."
		exitfunction
	endif
	
	select vtype
		case 0
			loopstep=4
		endcase

		case 1
			loopstep=4
		endcase

		case 2
			loopstep=1
		endcase

		case 3
			loopstep=1
		endcase

		case 4
			loopstep=1
		endcase
		
		case 5
			loopstep=2
		endcase

		case 6
			loopstep=4
		endcase
		
		case 7
			loopstep=8
		endcase
		
		case 8
			loopstep=8
		endcase

	endselect
	
	index=0
	stpos=mptr
	bpos=-1
	for addr = mptr to (mptr+msz)-loopstep step loopstep
		iptr = aryptr+get arrayptr item ptr(aryptr,index)
		select vtype
			case 0 
				value=peek integer(addr)
				poke integer iptr,value
			endcase

			case 1
				value#=peek float(addr)
				poke float iptr,value#
			endcase

			case 2
				inc bpos
				b=peek byte(addr)
				b1=peek byte(addr+1)
				if (addr-mptr)=msz-1 then exit
				if b>=32 and b<=127 and b1 = 0
					inc strcount
					if strcount =1
						iptr=get arrayptr item ptr(aryptr,strcount-1)
						poke dword iptr,stpos
						nbpos=bpos+1
					else
						if strcount > 1
							iptr=get arrayptr item ptr(aryptr,strcount-1)
							poke dword iptr,stpos+nbpos+1
							nbpos=bpos+1
						endif
					endif
				endif
			endcase

			case 3 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
			
			case 4 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
		
			case 5 
				value=peek word(addr)
				poke word iptr,value
			endcase

			case 6 
				value=peek dword(addr)
				poke dword iptr,value
			endcase
	
			case 7 
				value=peek double float(addr)
				poke double float iptr,value
			endcase
	
			case 8 
				value=peek double integer(addr)
				poke double integer iptr,value
			endcase
		endselect 		
		inc index
	next addr
endfunction


[version 0.12- back to strings for now, uses alloc, memblocks, banks. see attached input file]

+ Code Snippet
Rem Project: memory_to_array (including strings)
Rem Created: Tuesday, June 8, 2021

Rem ***** Main Source File *****
Rem ***** draft version 0.12 *****
backdrop off
sync on : sync rate 30 : sync

dim dwary(2) as dword // items=3 0-2  (notice not used "as string" we are storing the dword address that points the the actual text in memory)
dim strary(2) as string // items=3 0-2

dwptr as dword
dwptr = get arrayptr(dwary())

rem below for memblock memory
`memid=find free memblock()
`memptr=MakeMemoryFromFile(1,memid,"input.txt")

rem below for bank memory
`memid=find free bank()
`memptr=MakeMemoryFromFile(2,memid,"input.txt")
`memsz=get memblock size(memid)

rem below for ALLOC memory- use 0 for memid as n/a
memptr=MakeMemoryFromFile(3,0,"input.txt")

rem ok for both ALLOC and BANK memory - do not use for memblocks
memsz=memory size(memptr)

REM code below is for strings

if memptr > 0
	MakeArrayFromMemory(memptr,memsz,dwptr,2)
	cnt=array count(dwary())
	for i=0 to cnt 
		t$ = peek string(dwary(i))
		strary(i)= t$
		print strary(i)
	next i
endif

sync
wait key
undim dwary()
undim strary()

`if memblock exist(memid)=1 then delete memblock memid
if bank exist(memid)=1 then delete bank memid 
`free memptr
end

function MakeMemoryFromFile(mtype,memid,src$)
	// mtype: 1=memblock 2=bank 3=alloc
	if file exist(src$)=0 or mtype<1 or mtype>3
		exitfunction 0 
	endif

	if mtype=1
		mid=memid
		fid=find free file()
		open to read fid,src$
		make memblock from file mid,fid
		close file fid
		`fix code
		if memblock exist(mid)=0
			exitfunction 0 
		endif
		msz = Get Memblock Size(mid)
		tmid = Find Free Memblock()
		
		for b=0 to msz-1
			if memblock byte(mid, b) = 13 or memblock byte(mid, b) = 10
				write memblock byte mid,b,0
			endif  
		next b
		
		make memblock tmid,msz
		for b=0 to msz-1
			write memblock byte tmid,b,0
		next b
	
		tb=0
		for b=0 to msz-1
			byt=Memblock Byte(mid,b)
			if byt <> 0
				write memblock byte tmid,tb,byt
				inc tb
			else
				inc b
				inc tb
			endif
		next b
		
		if memblock exist(mid) then delete memblock mid
		make memblock mid,msz
		copy memblock tmid,mid,0,0,msz
		if memblock exist(tmid) then delete memblock tmid
		newmptr=get memblock ptr(mid)
	endif
	
	if mtype=2
		mid=memid
		make bank from file mid,src$
		`fix code
		if bank exist(mid)=0
			exitfunction 0 
		endif
		msz = Get Bank Size(mid)
		tmid = Find Free Bank()
		
		for b=0 to msz-1
			if bank byte(mid, b) = 13 or bank byte(mid, b) = 10
				write bank byte mid,b,0
			endif  
		next b
	
		make bank tmid,msz
		for b=0 to msz-1
			write bank byte tmid,b,0
		next b
	
		tb=0
		for b=0 to msz-1
			byt=Bank Byte(mid,b)
			if byt <> 0
				write bank byte tmid,tb,byt
				inc tb
			else
				inc b
				inc tb
			endif
		next b
		
		if bank exist(mid) then delete bank mid
		make bank mid,msz
		copy bank tmid,0,msz,mid,0
		if bank exist(mid) then delete bank tmid
		newmptr=get bank ptr(mid)		
	endif
	
	if mtype=3
		fsz=file size(src$)
		mptr=alloc Zeroed(fsz)
		fid=find free file()
		open to read fid,src$
		for addr=mptr to mptr+fsz-1
			read byte fid,byt
			poke byte addr,byt
		next addr	
		close file fid
		
		`fix memory code integrated
		msz = Memory Size(mptr)
		if msz=0
			exitfunction 0 
		endif
		
		for addr=mptr to mptr+msz-1
			if peek byte(addr) = 13 or peek byte(addr) = 10
				poke byte addr,0
			endif  
		next addr
	
		tmptr = alloc zeroed(msz)
		tb=0
		for addr=mptr to mptr+msz-1
			byt=peek byte(addr)
			if byt <> 0
				poke byte tmptr+tb,byt
				inc tb
			else
				inc addr
				inc tb
			endif
		next addr
		
		free mptr
		newmptr=alloc zeroed(msz)
		` copy mem to mem
		bpos=0
		for addr=tmptr to tmptr+msz-1
			byt=peek byte(addr)
			poke byte newmptr+bpos,byt
			inc bpos
		next addr
		free tmptr		
	endif 			
endfunction newmptr

function MakeArrayFromMemory(mptr,msz,aryptr,vtype)
	// vtype : no value type/integer=0, 1=float, 2=string, 3=boolean, 
	//         4=byte, 5=word, 6=dword, 7=double float, 8=double integer
	stpos as dword
	if vtype <0 or vtype >8 
		message "type is invalid, parse 1-8 only."
		exitfunction
	endif
	
	select vtype
		case 0
			loopstep=4
		endcase

		case 1
			loopstep=4
		endcase

		case 2
			loopstep=1
		endcase

		case 3
			loopstep=1
		endcase

		case 4
			loopstep=1
		endcase
		
		case 5
			loopstep=2
		endcase

		case 6
			loopstep=4
		endcase
		
		case 7
			loopstep=8
		endcase
		
		case 8
			loopstep=8
		endcase

	endselect
	
	index=0
	stpos=mptr
	bpos=-1
	for addr = mptr to (mptr+msz)-loopstep step loopstep
		iptr = aryptr+get arrayptr item ptr(aryptr,index)
		select vtype
			case 0 
				value=peek integer(addr)
				poke integer iptr,value
			endcase

			case 1
				value#=peek float(addr)
				poke float iptr,value#
			endcase

			case 2
				inc bpos
				b=peek byte(addr)
				b1=peek byte(addr+1)
				if (addr-mptr)=msz-1 then exit
				if b>=32 and b<=127 and b1 = 0
					inc strcount
					if strcount =1
						iptr=get arrayptr item ptr(aryptr,strcount-1)
						poke dword iptr,stpos
						nbpos=bpos+1
					else
						if strcount > 1
							iptr=get arrayptr item ptr(aryptr,strcount-1)
							poke dword iptr,stpos+nbpos+1
							nbpos=bpos+1
						endif
					endif
				endif
			endcase

			case 3 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
			
			case 4 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
		
			case 5 
				value=peek word(addr)
				poke word iptr,value
			endcase

			case 6 
				value=peek dword(addr)
				poke dword iptr,value
			endcase
	
			case 7 
				value=peek double float(addr)
				poke double float iptr,value
			endcase
	
			case 8 
				value=peek double integer(addr)
				poke double integer iptr,value
			endcase
		endselect 		
		inc index
	next addr
endfunction

Posted: 16th Mar 2021 21:26
i don't suppose a mod could correct the thread title "Stings" -> "Strings"? .. thanks
Posted: 17th Mar 2021 12:09
1st post now updated with v0.9 of the code.
Posted: 17th Mar 2021 22:29
1st post updated with v0.10 code. Only 2 functions required now : MakeMemoryFromFile(mtype,src$) and MakeArrayFromMemory(mptr,msz,aryptr,vtype)
Posted: 19th Mar 2021 9:51
ok that's strings, but you're probably wondering how to get memory containing floats, integers, bytes etc into an array. I will come to that. there are a couple of ways. I will show as soon as I get a bit more time. Although most of you experienced advanced programmers will probably have worked it out already. HINT: you can e.g. create a file list of e.g. floats, integers etc then use the functions above i.e. parsing as strings OR you can "poke" direct into a e.g. memblock although I found some issues which I'm trying to figure out why I'm getting issues. so the string way seems to work better than poking say a float into memory. the cast dword to float command doesn't seem to work for me either but again still looking into a lot of issues at the moment.
project is still WIP and working out what DBPro is doing internally. some weird results. Works currently really well with strings, so I would say go with string process for now if you want to use floats, bytes or whatever.
Posted: 19th Mar 2021 21:42
This is a basic program breaking down the steps of how to populate float array from a memblock. Same approach for a bank or alloc type memory.

+ Code Snippet
backdrop off
sync on: sync rate 30: sync
dim float_array(3) as float

fltptr=get arrayptr(float_array())

make memblock 1,16
mbptr=get memblock ptr(1)
mbsz=get memblock size(1)

poke float mbptr+0,1.876521
poke float mbptr+4,999.887766
poke float mbptr+8,123.571234
poke float mbptr+12,700000.1111111

print str$(peek float(mbptr+0),6)
print str$(peek float(mbptr+4),6)
print str$(peek float(mbptr+8),6)
print str$(peek float(mbptr+12),6)

for i=0 to 3
	iptr=get arrayptr item ptr(fltptr,i)
	poke float iptr,peek float((mbptr)+i*4)
	print str$(peek float(iptr),6)
next i

sync
wait key
end


of course for UDT arrays the approach is also the same except you need to get the offsets of the variable items. Will give example later. All very simple and straight forward.
Posted: 20th Mar 2021 7:11
Example code of Memory to UDT array. This is a breakdown of how to "poke" data into memory, take that memory info and store in UDT array. In this simple case a 2 variable UDT structure.

+ Code Snippet
Rem Project: memory_to_float_UDT_array_test1
Rem Created: Friday, March 19, 2021
Rem ***** Main Source File *****
backdrop off
sync on: sync rate 30: sync

type float_items
	id as integer
	value as float
endtype

dim float_array(3) as float_items

fltptr=get arrayptr(float_array())

make memblock 1,16
mbptr=get memblock ptr(1)
mbsz=get memblock size(1)

poke float mbptr+0,1.876521
poke float mbptr+4,999.887766
poke float mbptr+8,123.571234
poke float mbptr+12,700000.1111111

for i=0 to 3
	iptr1=get arrayptr item ptr(fltptr,i)+0
	iptr2=get arrayptr item ptr(fltptr,i)+4
	poke integer iptr1,i+1
	poke float iptr2,peek float((mbptr)+i*4)
	`print str$(peek integer(iptr1))
	`print str$(peek float(iptr2),6)
next i

ShowArrayStatus(fltptr,1,1,1,"dump.txt")
ShowArrayStatus(fltptr,2,1,1,"dump2.txt")
sync
wait key
end

remstart
0 = Integer
1 = Float
2 = String
3 = Boolean
4 = Byte
5 = Word
6 = Dword
7 = Double float
8 = Double integer	
remend

function ShowArrayStatus(ptr,field,outtofile,fid,fname$)
	if outtofile=1
		if fname$="" or fid = 0
			warningmessage "(ShowArrayStatus) No filename OR file ID specified!"
			exitfunction
		endif
		DeleteFile(fname$)
		open to write fid,fname$
	endif

	fo = get arrayptr field offset(ptr,field)
	ftyp = get arrayptr field type(ptr,field)
    ptrcnt=get arrayptr count(ptr) // number of items in array ptr e.g. 2 -> raw_name, id (0 & 4 offset)   
    
    for p=0 to ptrcnt // for each item in arrayptr
        iptr = get arrayptr item ptr(ptr,p)+fo // get the pointer to array item i.e. string (dword) raw_name
		rem add more conditions here for the different types as you need them....
		if ftyp = 0
			t$=str$(peek integer(iptr))
		else
			if ftyp = 1
				t$=str$(peek float(iptr))
			else
				if ftyp = 2 // string
					t$=peek string(*iptr)
				else
					if ftyp = 3 or ftyp = 4 // Boolean or Byte
						t$=str$(peek byte(iptr))			
					endif
				endif
			endif
		endif
       	if t$ <> "" then print t$ // display item string at specified address, use * to return string correctly or get garbage
		
		if outtofile = 1
			write string fid,"Item "+str$(p+1)+" contains:  "+t$
		endif
    next p

	if outtofile = 1
		if file open(fid) then close file fid 	
	endif 
	
endfunction

function DeleteFile(filetodel$)
	if file exist(filetodel$) then delete file (filetodel$)
endfunction


I've added one of my standard library functions that display the contents of the array pointer and has the option to store to file(s) per field (or offset).
I havent stored the integer value into memory but this could be easily done, I'm just being lazy today.

Now the next part would be to take the basic code and put into functions using the MakeMemoryFromFile and MakeArrayFromMemory. I use the word memory as I'm trying to keep it generic as I want the option to create a memblock, bank (Mstrix1Utils) or Alloc memory (Matrix1Utils).

More to come:

[update-code updated to show how to poke the integers into memory and then poke them into the UDT array at the correct offset, very very easy]

+ Code Snippet
Rem Project: memory_to_float_UDT_array_test1
Rem Created: Friday, March 19, 2021
Rem ***** Main Source File *****
backdrop off
sync on: sync rate 30: sync

type float_items
	id as integer
	value as float
endtype

dim float_array(3) as float_items

fltptr=get arrayptr(float_array())

make memblock 1,32
mbptr=get memblock ptr(1)
mbsz=get memblock size(1)

poke integer mbptr+0,1
poke integer mbptr+4,2
poke integer mbptr+8,3
poke integer mbptr+12,4
poke float mbptr+16,1.876521
poke float mbptr+20,999.887766
poke float mbptr+24,123.571234
poke float mbptr+28,700000.1111111

for i=0 to 3
	iptr1=get arrayptr item ptr(fltptr,i)+0
	iptr2=get arrayptr item ptr(fltptr,i)+4
	poke integer iptr1,peek integer((mbptr)+i*4)
	poke float iptr2,peek float((mbptr)+(i*4)+16)
next i

ShowArrayStatus(fltptr,1,1,1,"dump.txt")
ShowArrayStatus(fltptr,2,1,1,"dump2.txt")
sync
wait key
end

remstart
0 = Integer
1 = Float
2 = String
3 = Boolean
4 = Byte
5 = Word
6 = Dword
7 = Double float
8 = Double integer	
remend

function ShowArrayStatus(ptr,field,outtofile,fid,fname$)
	if outtofile=1
		if fname$="" or fid = 0
			warningmessage "(ShowArrayStatus) No filename OR file ID specified!"
			exitfunction
		endif
		DeleteFile(fname$)
		open to write fid,fname$
	endif

	fo = get arrayptr field offset(ptr,field)
	ftyp = get arrayptr field type(ptr,field)
    ptrcnt=get arrayptr count(ptr) // number of items in array ptr e.g. 2 -> raw_name, id (0 & 4 offset)   
    
    for p=0 to ptrcnt // for each item in arrayptr
        iptr = get arrayptr item ptr(ptr,p)+fo // get the pointer to array item i.e. string (dword) raw_name
		rem add more conditions here for the different types as you need them....
		if ftyp = 0
			t$=str$(peek integer(iptr))
		else
			if ftyp = 1
				t$=str$(peek float(iptr))
			else
				if ftyp = 2 // string
					t$=peek string(*iptr)
				else
					if ftyp = 3 or ftyp = 4 // Boolean or Byte
						t$=str$(peek byte(iptr))			
					endif
				endif
			endif
		endif
       	if t$ <> "" then print t$ // display item string at specified address, use * to return string correctly or get garbage
		
		if outtofile = 1
			write string fid,"Item "+str$(p+1)+" contains:  "+t$
		endif
    next p

	if outtofile = 1
		if file open(fid) then close file fid 	
	endif 
	
endfunction

function DeleteFile(filetodel$)
	if file exist(filetodel$) then delete file (filetodel$)
endfunction

Posted: 21st Mar 2021 20:59
UDT array (integer and string):

+ Code Snippet
Rem Project: memory_to_string_UDT_array_test3
Rem Created: Saturday, March 20, 2021
Rem ***** Main Source File *****
backdrop off
sync on: sync rate 30: sync

type dword_items
	id as integer
	value as dword
endtype

dim dword_array(4) as dword_items

fltptr=get arrayptr(dword_array())

numberofints=5
numberofdword=5
sizeofints=4
sizeofdword=4
totalbytes = (numberofints*sizeofints) + (numberofdword*sizeofdword)  
make memblock 1,totalbytes
mbptr=get memblock ptr(1)
mbsz=get memblock size(1)

poke integer mbptr+0,1
poke integer mbptr+4,2
poke integer mbptr+8,3
poke integer mbptr+12,4
poke integer mbptr+16,5

a$="This is string number 1."
b$="This is string number 2."
c$="This is string number 3."
d$="This is string number 4."
e$="This is string number 5."

a as dword
b as dword
c as dword
d as dword
e as dword

a=get string ptr(a$)
b=get string ptr(b$)
c=get string ptr(c$)
d=get string ptr(d$)
e=get string ptr(e$)
poke dword mbptr+20,a
poke dword mbptr+24,b
poke dword mbptr+28,c
poke dword mbptr+32,d
poke dword mbptr+36,e

for i=0 to get arrayptr count(fltptr)
	iptr1=get arrayptr item ptr(fltptr,i)+0
	iptr2=get arrayptr item ptr(fltptr,i)+4
	poke integer iptr1,peek integer((mbptr)+i*4)
	poke dword iptr2,peek dword((mbptr)+(i*4)+20)
	print peek string(*iptr2)
next i

ShowArrayStatus(fltptr,1,1,1,"dump.txt")
ShowArrayStatus(fltptr,2,1,1,"dump2.txt")

sync
wait key
end

remstart
0 = Integer
1 = Float
2 = String
3 = Boolean
4 = Byte
5 = Word
6 = Dword
7 = Double float
8 = Double integer	
remend

function ShowArrayStatus(ptr,field,outtofile,fid,fname$)
	if outtofile=1
		if fname$="" or fid = 0
			warningmessage "(ShowArrayStatus) No filename OR file ID specified!"
			exitfunction
		endif
		DeleteFile(fname$)
		open to write fid,fname$
	endif

	fo = get arrayptr field offset(ptr,field)
	ftyp = get arrayptr field type(ptr,field)
    ptrcnt=get arrayptr count(ptr) // number of items in array ptr e.g. 2 -> raw_name, id (0 & 4 offset)   
    
    for p=0 to ptrcnt // for each item in arrayptr
        iptr = get arrayptr item ptr(ptr,p)+fo // get the pointer to array item i.e. string (dword) raw_name
		rem add more conditions here for the different types as you need them....
		if ftyp = 0
			t$=str$(peek integer(iptr))
		else
			if ftyp = 1
				t$=str$(peek float(iptr))
			else
				if ftyp = 2 // string
					t$=peek string(*iptr)
				else
					if ftyp = 3 or ftyp = 4 // Boolean or Byte
						t$=str$(peek byte(iptr))			
					else 
						if ftyp = 6
							t$=str$(peek dword(iptr))
						endif
					endif
				endif
			endif
		endif
       	if t$ <> "" then print t$ // display item string at specified address, use * to return string correctly or get garbage
		
		if outtofile = 1
			write string fid,"Item "+str$(p+1)+" contains:  "+t$
		endif
    next p

	if outtofile = 1
		if file open(fid) then close file fid 	
	endif 
	
endfunction

function DeleteFile(filetodel$)
	if file exist(filetodel$) then delete file (filetodel$)
endfunction
Posted: 22nd Mar 2021 3:39
i don't suppose a mod could correct the thread title

done.
Posted: 12th Apr 2021 11:15
still working on this on and off, other projects ongoing at the moment.
Posted: 6th Jun 2021 20:30
more updates to come this week, working on this currently.
Posted: 11th Jun 2021 21:25
see updates on first post.
Posted: 12th Nov 2021 20:28
made some updates over last couple of days. You can set which memory type you want to use 1=Memblock, 2=Bank, 3=Alloc by setting the constant var MEMTYPE at beginning of program.
The source file will then be read obtain the # of rows containing the text so that the arrays can be initialised accordingly and no need for array insert at bottom type commands which are slow.
The file data is then stored in memory and converted to an array list of DWORDS that point to the STRING data which is then stored into the string ARRAY and the memory deleted.

+ Code Snippet
Rem Project: memory_to_array (including strings)
Rem Created: Tuesday, June 8, 2021
Rem Updated: Friday, November 12, 2021
Rem ***** Main Source File *****
Rem ***** draft version 0.13 *****
backdrop off
sync on : sync rate 30 : sync

#constant memtype 3
src$="input.txt"
`src$="chapel.obj"

count=GetFileRows(src$)

dim dwary(count) as dword // items=3 0-2  (notice not used "as string" we are storing the dword address that points to the actual text in memory)
dim strary(count) as string // items=3 0-2

dwptr as dword
dwptr = get arrayptr(dwary())

rem below for memblock memory
if memtype=1
	memid=find free memblock()
	memptr=MakeMemoryFromFile(1,memid,src$)
	memsz=get memblock size(memid)
else 
	if memtype=2
		rem below for bank memory
		memid=find free bank()
		memptr=MakeMemoryFromFile(2,memid,src$)
		memsz=memory size(memptr)
	else
		if memtype=3
			rem below for ALLOC memory- use 0 for memid as n/a
			memptr=MakeMemoryFromFile(3,0,src$)
			memsz=memory size(memptr)
		endif
	endif
endif

REM code below is for strings
if memptr > 0
	MakeArrayFromMemory(memptr,memsz,dwptr,2)
	print "processing..."
	sync
	cnt=array count(dwary())
	for i=0 to cnt 
		t$ = peek string(dwary(i))
		strary(i)= t$
		print strary(i)
	next i
endif

`delete memory - as appropriate
if memtype=1
	if memblock exist(memid)=1 then delete memblock memid
else
	if memtype=2
		if bank exist(memid)=1 then delete bank memid 
	else
		if memtype=3
			free memptr
		endif
	endif
endif

print "press a key."
sync
wait key
undim dwary()
undim strary()

`message "ended normally!!"
end

function GetFileRows(src$) 
	r=0
	mid=reserve free bank()
	make bank from file mid,src$
	mptr=get bank ptr(mid)
	msz=get bank size(mid)
	for a=mptr to mptr+msz
		byt=peek byte(a)
		` 2 scenarios 1=byt = CR or NL and prev byt is a valid ascii char and next byt not a null terminator (0)
		`             2=byt is CR and next byt is NL and next byt is not a null terminator  
		if (byt=(0xa or byt=0xd) and peek byte(a-1) >=32 and peek byte(a-1) <=127 and peek byte(a+1) <>0) _ 
				or (byt = 13 and peek byte(a+1)=10 and peek byte(a+2) <>0  ) then inc r
	next a
	delete bank mid
	release reserved bank mid
endfunction r

function MakeMemoryFromFile(mtype,memid,src$)
	// mtype: 1=memblock 2=bank 3=alloc
	if file exist(src$)=0 or mtype<1 or mtype>3
		exitfunction 0 
	endif

	if mtype=1
		mid=memid
		fid=find free file()
		open to read fid,src$
		make memblock from file mid,fid
		close file fid
		`fix code
		if memblock exist(mid)=0
			exitfunction 0 
		endif
		msz = Get Memblock Size(mid)
		tmid = Find Free Memblock()
		
		for b=0 to msz-1
			if memblock byte(mid, b) = 13 or memblock byte(mid, b) = 10
				write memblock byte mid,b,0
			endif  
		next b
		
		make memblock tmid,msz
		for b=0 to msz-1
			write memblock byte tmid,b,0
		next b
	
		tb=0
		for b=0 to msz-1
			byt=Memblock Byte(mid,b)
			if byt <> 0
				write memblock byte tmid,tb,byt
				inc tb
			else
				inc b
				inc tb
			endif
		next b
		
		if memblock exist(mid) then delete memblock mid
		make memblock mid,msz
		copy memblock tmid,mid,0,0,msz
		if memblock exist(tmid) then delete memblock tmid
		newmptr=get memblock ptr(mid)
	endif
	
	if mtype=2
		mid=memid
		make bank from file mid,src$
		`fix code
		if bank exist(mid)=0
			exitfunction 0 
		endif
		msz = Get Bank Size(mid)
		tmid = Find Free Bank()
		mptr=get bank ptr(mid)
		for b=0 to msz-1
			if bank byte(mid, b) = 0xd or bank byte(mid, b) = 0xa
				write bank byte mid,b,0
			endif  
		next b

		make bank tmid,msz
		for b=0 to msz-1
			write bank byte tmid,b,0
		next b
	
		tb=0
		for b=0 to msz-1
			byt=Bank Byte(mid,b)  
			if byt <> 0 
				write bank byte tmid,tb,byt
				inc tb
			else
				inc b
				inc tb
			endif
		next b
		
		if bank exist(mid) then delete bank mid
		make bank mid,msz
		copy bank tmid,0,msz,mid,0
		if bank exist(mid) then delete bank tmid
		newmptr=get bank ptr(mid)		
	endif
	
	if mtype=3
		fsz=file size(src$)
		mptr=alloc Zeroed(fsz)
		fid=find free file()
		open to read fid,src$
		for addr=mptr to mptr+fsz-1
			read byte fid,byt
			poke byte addr,byt
		next addr	
		close file fid
		
		`fix memory code integrated
		msz = Memory Size(mptr)
		if msz=0
			exitfunction 0 
		endif
		
		for addr=mptr to mptr+msz-1
			if peek byte(addr) = 13 or peek byte(addr) = 10
				poke byte addr,0
			endif  
		next addr

		tmptr = alloc zeroed(msz)
		tb=0
		for addr=mptr to mptr+msz-1
			byt=peek byte(addr)
			if byt <> 0
				poke byte tmptr+tb,byt
				inc tb
			else
				inc addr
				inc tb
			endif
		next addr
		
		free mptr
		newmptr=alloc zeroed(msz)
		` copy mem to mem
		bpos=0
		for addr=tmptr to tmptr+msz-1
			byt=peek byte(addr)
			poke byte newmptr+bpos,byt
			inc bpos
		next addr
		free tmptr
	endif 			
endfunction newmptr

function MakeArrayFromMemory(mptr,msz,aryptr,vtype)
	// vtype : no value type/integer=0, 1=float, 2=string, 3=boolean, 
	//         4=byte, 5=word, 6=dword, 7=double float, 8=double integer
	stpos as dword
	if vtype <0 or vtype >8 
		message "type is invalid, parse 1-8 only."
		exitfunction
	endif
	
	select vtype
		case 0
			loopstep=4
		endcase

		case 1
			loopstep=4
		endcase

		case 2
			loopstep=1
		endcase

		case 3
			loopstep=1
		endcase

		case 4
			loopstep=1
		endcase
		
		case 5
			loopstep=2
		endcase

		case 6
			loopstep=4
		endcase
		
		case 7
			loopstep=8
		endcase
		
		case 8
			loopstep=8
		endcase

	endselect
	
	index=0
	stpos=mptr
	bpos=-1
	for addr = mptr to (mptr+msz)-loopstep step loopstep
		iptr = aryptr+get arrayptr item ptr(aryptr,index)
		select vtype
			case 0 
				value=peek integer(addr)
				poke integer iptr,value
			endcase

			case 1
				value#=peek float(addr)
				poke float iptr,value#
			endcase

			case 2
				inc bpos
				b=peek byte(addr)
				b1=peek byte(addr+1)
				if (addr-mptr)=msz-1 then exit

				if b>=32 and b<=127 and b1 = 0
					if b1 = 0
						inc strcount
						if strcount =1
							iptr=get arrayptr item ptr(aryptr,strcount-1)
							poke dword iptr,stpos
							nbpos=bpos+1
						else
							if strcount > 1
								iptr=get arrayptr item ptr(aryptr,strcount-1)
								poke dword iptr,stpos+nbpos+1
								nbpos=bpos+1
							endif
						endif
					endif
				endif
			endcase

			case 3 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
			
			case 4 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
		
			case 5 
				value=peek word(addr)
				poke word iptr,value
			endcase

			case 6 
				value=peek dword(addr)
				poke dword iptr,value
			endcase
	
			case 7 
				value=peek double float(addr)
				poke double float iptr,value
			endcase
	
			case 8 
				value=peek double integer(addr)
				poke double integer iptr,value
			endcase
		endselect 		
		inc index
	next addr
endfunction
Posted: 16th Nov 2021 21:06
new update to come soon as the last version not 100% correct.
Posted: 19th Nov 2021 6:36
update - only uses alloc for now - need to add code again for memblock, bank or you guys could have a go.

+ Code Snippet
Rem Project: memory_to_array (including strings)
Rem Created: Tuesday, June 8, 2021
Rem Updated: Friday, November 12/18, 2021
Rem ***** Main Source File *****
Rem ***** draft version 0.12c *****
backdrop off
sync on : sync rate 30 : sync

#constant memtype 3
#constant MXROWS 30 // display XX number of rows in print statement (for very large files)
`src$="input.txt" // has both CR + NL i.e. 0xd or 13 and 0xa or 10 bytes
`src$="chapel.obj" // has no CR only NL i.e. 0xa or 10 byte
src$="Chomper - Feeder Zombie.obj" //has both CR + NL

`retain just the filename text without extension
shortfilename$=GetFileShort$(src$)

`memptr=nptr
memptr=MakeMemoryFromFile(mtype,memid,src$)
memsz=memory size (memptr) //nsz
rows=GetMemRows(memptr,memsz)

dim dwary(rows-1) as dword
dim strary(rows-1) as string 
dwptr as dword
dwptr=get arrayptr (dwary())

REM code below is for strings
if memptr > 0
	MakeArrayFromMemory(memptr,memsz,dwptr,2)
	print "processing..."
	sync
	cnt=array count(dwary())
	`output a file just to show it works
	outfile$=shortfilename$+"_dwary_dump.txt"
	DeleteFile(outfile$)
	open to write 1,outfile$
	for i=0 to cnt 
		t$ = peek string(dwary(i))
		write string 1,"i: "+str$(i)+chr$(9)+str$(dwary(i))+chr$(9)+t$
		strary(i)= t$
		// change MXROWS constant or remove condition statement altogether
		if i<=MXROWS and MXROWS <=rows then print strary(i)
	next i
	close file 1
endif

sync
wait key
free memptr
undim dwary()
undim strary()
end

function DeleteFile(f$)
	if file exist(f$)=1 then delete file f$
endfunction

function GetFileShort$(src$) 
	longfilename$=src$
	shortfilename$=extract filename$(longfilename$)
	shortfilenameext$=extract fileext$(longfilename$)
	shortfilenameextlen  = fast len (shortfilenameext$)
	shortfilename$ = fast left$(shortfilename$,fast len (shortfilename$)-shortfilenameextlen) 
endfunction shortfilename$

function MakeMemoryFromFile(mtype,memid,src$)
	fsz=file size(src$)
	aptr=alloc(fsz)
	v as byte
	i=-1
	ret=0
	open to read 1,src$
		repeat
		read byte 1,v
		inc i
		poke byte aptr+i,v
		until file end(1)=1
	close file 1 
	mptr=aptr
	msz=fsz
	
	byt as byte
	byt1 as byte
	asc_count=0 : cr_count=0 : nl_count=0
	isok=0
	ret=0
	for a=mptr to (mptr+msz)-1
		byt = peek byte(a)
		if a <=(mptr+msz)-1 
			byt1 = peek byte(a+1)
			isok=1
		else
			isok=0
		endif
	
		if byt >=0x20 and byt <=0x7f
			inc asc_count
		else
			if byt = 0xd and isok=1 and byt1 = 0xa
				inc cr_count	
			else
				if byt = 0xa
					inc nl_count
				endif
			endif
		endif
	next a
	
	totbytes = asc_count + cr_count + nl_count
	
	fsz=file size(src$)
	if cr_count > 0 and nl_count > 0 and cr_count = nl_count
		newmembytes = asc_count + ((cr_count + nl_count) / 2)  
	else 
		if cr_count = 0 and nl_count > 0
			newmembytes = asc_count + nl_count // will be the same as byte 0xa will be replaced with NULL terminal byte markers
		endif
	endif
	
	` create new memory with 0's (terminators)
	nptr = alloc zeroed(newmembytes)
	nsz=newmembytes
	isok=0
	x=nptr
	for b=mptr to (mptr+msz)-1
		byt = peek byte(b)
		if b<=(mptr+msz)-1 
			byt1 = peek byte(b+1)
			isok=1
		else
			isok=0
		endif
	
		if byt >=0x20 and byt <=0x7f
			poke byte x,byt
			inc x
		else
			if byt = 0xd and isok=1 and byt1 = 0xa
				inc x
				inc b,1
			else
				if byt = 0xa
					inc x
				endif
			endif
		endif
	next b	
	
	free mptr
endfunction nptr

function GetMemRows(mptr,msz)
	ret=0
	for b=mptr to (mptr+msz)-1
		byt = peek byte(b)
		if b<=(mptr+msz)-1 
			byt1 = peek byte(b+1)
			isok=1
		else
			isok=0
		endif
	
		if byt=0
			inc ret
		endif
	next b	
endfunction ret

function MakeArrayFromMemory(mptr,msz,aryptr,vtype)
	// vtype : no value type/integer=0, 1=float, 2=string, 3=boolean, 
	//         4=byte, 5=word, 6=dword, 7=double float, 8=double integer
	stpos as dword
	if vtype <0 or vtype >8 
		message "type is invalid, parse 1-8 only."
		exitfunction
	endif
	
	select vtype
		case 0
			loopstep=4
		endcase

		case 1
			loopstep=4
		endcase

		case 2
			loopstep=1
		endcase

		case 3
			loopstep=1
		endcase

		case 4
			loopstep=1
		endcase
		
		case 5
			loopstep=2
		endcase

		case 6
			loopstep=4
		endcase
		
		case 7
			loopstep=8
		endcase
		
		case 8
			loopstep=8
		endcase

	endselect
	
	stpos=mptr
	bpos=-1
	
	for addr = mptr to (mptr+msz)-loopstep step loopstep
		select vtype
			case 0 
				value=peek integer(addr)
				poke integer iptr,value
			endcase

			case 1
				value#=peek float(addr)
				poke float iptr,value#
			endcase

			case 2
				inc bpos
				b=peek byte(addr)
				b1=peek byte(addr+1)
				if (addr-mptr)=msz-1 then exit

				if (b>=0x20 and b<=0x7f and b1 = 0) or (b=0 and b1 = 0)
					if b1 = 0
						inc strcount
						if strcount =1
							iptr=get arrayptr item ptr(aryptr,strcount-1)
							poke dword iptr,stpos
							nbpos=bpos+1
						else
							if strcount >1
								iptr=get arrayptr item ptr(aryptr,strcount-1)
								poke dword iptr,stpos+nbpos+1
								nbpos=bpos+1
							endif
						endif
					endif
				endif
			endcase

			case 3 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
			
			case 4 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
		
			case 5 
				value=peek word(addr)
				poke word iptr,value
			endcase

			case 6 
				value=peek dword(addr)
				poke dword iptr,value
			endcase
	
			case 7 
				value=peek double float(addr)
				poke double float iptr,value
			endcase
	
			case 8 
				value=peek double integer(addr)
				poke double integer iptr,value
			endcase
		endselect 		
	next addr
endfunction
Posted: 19th Nov 2021 7:05
added MakeFileFromMemory function. This is fast. more to come.

+ Code Snippet
Rem Project: memory_to_array (including strings)
Rem Created: Tuesday, June 8, 2021
Rem Updated: Friday, November 12/18, 2021
Rem ***** Main Source File *****
Rem ***** draft version 0.12c *****
backdrop off
sync on : sync rate 30 : sync

#constant memtype 3
#constant MXROWS 30 // display XX number of rows in print statement (for very large files)
`src$="input.txt" // has both CR + NL i.e. 0xd or 13 and 0xa or 10 bytes
`src$="chapel.obj" // has no CR only NL i.e. 0xa or 10 byte
src$="Chomper - Feeder Zombie.obj" //has both CR + NL

`retain just the filename text without extension
shortfilename$=GetFileShort$(src$)

`memptr=nptr
memptr=MakeMemoryFromFile(mtype,memid,src$)
memsz=memory size (memptr) //nsz
rows=GetMemRows(memptr,memsz)

dim dwary(rows-1) as dword
dim strary(rows-1) as string 
dwptr as dword
dwptr=get arrayptr (dwary())

REM code below is for strings
if memptr > 0
	MakeArrayFromMemory(memptr,memsz,dwptr,2)
	print "processing..."
	sync
	cnt=array count(dwary())
	`output a file just to show it works
	outfile$=shortfilename$+"_dwary_dump.txt"
	DeleteFile(outfile$)
	MakeFileFromMemory(memptr,outfile$)
	`open to write 1,outfile$
	for i=0 to cnt 
	`	t$ = peek string(dwary(i))
	`	write string 1,"i: "+str$(i)+chr$(9)+str$(dwary(i))+chr$(9)+t$
	`	strary(i)= t$
		// change MXROWS constant or remove condition statement altogether
		if i<=MXROWS and MXROWS <=rows then print strary(i)
	next i
	`close file 1
endif

sync
wait key
free memptr
undim dwary()
undim strary()
end

function DeleteFile(f$)
	if file exist(f$)=1 then delete file f$
endfunction

function GetFileShort$(src$) 
	longfilename$=src$
	shortfilename$=extract filename$(longfilename$)
	shortfilenameext$=extract fileext$(longfilename$)
	shortfilenameextlen  = fast len (shortfilenameext$)
	shortfilename$ = fast left$(shortfilename$,fast len (shortfilename$)-shortfilenameextlen) 
endfunction shortfilename$

function MakeFileFromMemory(mptr,f$)
	fid=reserve free file()
	open to write fid,f$
	msz=memory size(mptr)
	for a=mptr to mptr+msz-1
		if peek byte(a) <> 0 
		v$=v$+chr$(peek byte(a))
		else
			write string fid,v$	
			v$=""
		endif 	
	next a 
	close file fid
	release reserved file fid
endfunction

function MakeMemoryFromFile(mtype,memid,src$)
	fsz=file size(src$)
	aptr=alloc(fsz)
	v as byte
	i=-1
	ret=0
	open to read 1,src$
		repeat
		read byte 1,v
		inc i
		poke byte aptr+i,v
		until file end(1)=1
	close file 1 
	mptr=aptr
	msz=fsz
	
	byt as byte
	byt1 as byte
	asc_count=0 : cr_count=0 : nl_count=0
	isok=0
	ret=0
	for a=mptr to (mptr+msz)-1
		byt = peek byte(a)
		if a <=(mptr+msz)-1 
			byt1 = peek byte(a+1)
			isok=1
		else
			isok=0
		endif
	
		if byt >=0x20 and byt <=0x7f
			inc asc_count
		else
			if byt = 0xd and isok=1 and byt1 = 0xa
				inc cr_count	
			else
				if byt = 0xa
					inc nl_count
				endif
			endif
		endif
	next a
	
	totbytes = asc_count + cr_count + nl_count
	
	fsz=file size(src$)
	if cr_count > 0 and nl_count > 0 and cr_count = nl_count
		newmembytes = asc_count + ((cr_count + nl_count) / 2)  
	else 
		if cr_count = 0 and nl_count > 0
			newmembytes = asc_count + nl_count // will be the same as byte 0xa will be replaced with NULL terminal byte markers
		endif
	endif
	
	` create new memory with 0's (terminators)
	nptr = alloc zeroed(newmembytes)
	nsz=newmembytes
	isok=0
	x=nptr
	for b=mptr to (mptr+msz)-1
		byt = peek byte(b)
		if b<=(mptr+msz)-1 
			byt1 = peek byte(b+1)
			isok=1
		else
			isok=0
		endif
	
		if byt >=0x20 and byt <=0x7f
			poke byte x,byt
			inc x
		else
			if byt = 0xd and isok=1 and byt1 = 0xa
				inc x
				inc b,1
			else
				if byt = 0xa
					inc x
				endif
			endif
		endif
	next b	
	
	free mptr
endfunction nptr

function GetMemRows(mptr,msz)
	ret=0
	for b=mptr to (mptr+msz)-1
		byt = peek byte(b)
		if b<=(mptr+msz)-1 
			byt1 = peek byte(b+1)
			isok=1
		else
			isok=0
		endif
	
		if byt=0
			inc ret
		endif
	next b	
endfunction ret

function MakeArrayFromMemory(mptr,msz,aryptr,vtype)
	// vtype : no value type/integer=0, 1=float, 2=string, 3=boolean, 
	//         4=byte, 5=word, 6=dword, 7=double float, 8=double integer
	stpos as dword
	if vtype <0 or vtype >8 
		message "type is invalid, parse 1-8 only."
		exitfunction
	endif
	
	select vtype
		case 0
			loopstep=4
		endcase

		case 1
			loopstep=4
		endcase

		case 2
			loopstep=1
		endcase

		case 3
			loopstep=1
		endcase

		case 4
			loopstep=1
		endcase
		
		case 5
			loopstep=2
		endcase

		case 6
			loopstep=4
		endcase
		
		case 7
			loopstep=8
		endcase
		
		case 8
			loopstep=8
		endcase

	endselect
	
	stpos=mptr
	bpos=-1
	
	for addr = mptr to (mptr+msz)-loopstep step loopstep
		select vtype
			case 0 
				value=peek integer(addr)
				poke integer iptr,value
			endcase

			case 1
				value#=peek float(addr)
				poke float iptr,value#
			endcase

			case 2
				inc bpos
				b=peek byte(addr)
				b1=peek byte(addr+1)
				if (addr-mptr)=msz-1 then exit

				if (b>=0x20 and b<=0x7f and b1 = 0) or (b=0 and b1 = 0)
					if b1 = 0
						inc strcount
						if strcount =1
							iptr=get arrayptr item ptr(aryptr,strcount-1)
							poke dword iptr,stpos
							nbpos=bpos+1
						else
							if strcount >1
								iptr=get arrayptr item ptr(aryptr,strcount-1)
								poke dword iptr,stpos+nbpos+1
								nbpos=bpos+1
							endif
						endif
					endif
				endif
			endcase

			case 3 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
			
			case 4 
				value=peek byte(addr)
				poke byte iptr,value
			endcase
		
			case 5 
				value=peek word(addr)
				poke word iptr,value
			endcase

			case 6 
				value=peek dword(addr)
				poke dword iptr,value
			endcase
	
			case 7 
				value=peek double float(addr)
				poke double float iptr,value
			endcase
	
			case 8 
				value=peek double integer(addr)
				poke double integer iptr,value
			endcase
		endselect 		
	next addr
endfunction
Posted: 6th Mar 2022 6:07
more updates to this coming soon, flitting between work projects , c+ and dbpro and other projects. it's a crazy time at the moment.