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.

Code Snippets / [DBP] Memory to Array - works with strings

Author
Message
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 15th Mar 2021 14:09 Edited at: 18th Mar 2021 13:50
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 Memblocks and Banks (Matrix1Utils by IanM).
[update17Mar2021:latest version 0.10: code now only uses 2 functions MakeMemoryFromFile(mtype,src$) and MakeArrayFromMemory(mptr,msz,aryptr,vtype). see attached zip file for 0.10 ]


[update17Mar2021:latest version 0.9: integrated the FixMemory function into the MakeMemoryFromFile function. see attached zip file for 0.9. more to come ]


[update17Mar2021:updated code to use ALLOC memory to MAKEARRAYFROMMEMORY-added an interim FIXMEMORY function which will be integrated eventually into the MakeMemoryFromFile function. Testing still ongoing and tweaking here and there. IF statements replaced with SELECT CASE. + other tweaks here and there and fine tuning. The final version will just be using all PTRs for both MEMBLOCK/BANK mem types. Will be testing out on UDT arrays and making updates to the code to cater for those array types, so haven't forgotten. I'm also planning to get the code to auto populate that actual string array e.g. STRARY(), this will come soon when I do testing on UDT arrays. Added the project file in a zip bottom of thread and will update this with each progressive version, hopefully it can only get better. C+ version on it's way soon so you can use a DBPro command instead. That will need more thought/testing.]





[update16Mar2021:17:44-found a fix for the make memblock/bank from file-will post once tested properly and code as water tight as a ducks ...... ]

I will be adding c+ equivalent code in VS2019 i.e. a DBP command to do the same, bit more complex but quite straight forward plus a lot more checking.

here is full draft code (quick knock up code), subject to change/optimization/efficiency. You just create the memory and an array of said type i.e. integer=0, 1=float, 2=string, 3=boolean, 4=byte, 5=word, 6=dword, 7=double float, 8=double integer in this example, I have used dword type (2) and alloc type of memory. Notice I have used DWORD type and not STRING. I've left in STRING type for now, but is probably redundant here. I've added a 2nd array of string type which can then be used to populate the actual text data and then you delete the DWORD array and lastly memory . I'm looking into using the link array which I've used before which is very handy. Will be better in C+, which maybe by the end of the week I can have implemented as a new DBPro command . might replace the if.. then with select statements ...

[update 4:16Mar2021]
You can use the attached .txt file or create your own. Now can load in a file into a memblock/bank and save to array. A lot more to do to the code, and there is always a reason why I have written the code the way it is. Still WIP. Obviously you can remove the code that you don't want, so if you want to use banks instead of memblocks remove the code relating to memblocks etc. The current code is using the memblock, so the bank functions/code can be removed from the source. It's up to you-> Memblocks; Banks or Alloc reserved memory.
Do what you want with the code, make it better, report any issues and constructive criticism please. As it's still ongoing, code will change dramatically over the next few days/weeks. DBPro commands to be added soon and maybe AppGameKit all in C+



[update3:16Mar2021]
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others

Attachments

Login to view attachments
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 16th Mar 2021 21:26 Edited at: 16th Mar 2021 21:27
i don't suppose a mod could correct the thread title "Stings" -> "Strings"? .. thanks
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 17th Mar 2021 12:09
1st post now updated with v0.9 of the code.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
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)
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 19th Mar 2021 09:51 Edited at: 19th Mar 2021 10:00
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.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 19th Mar 2021 21:42 Edited at: 19th Mar 2021 21:45
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.



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.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 20th Mar 2021 07:11 Edited at: 20th Mar 2021 07:28
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.



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]

Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
16
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 21st Mar 2021 20:59 Edited at: 22nd Mar 2021 01:49
UDT array (integer and string):

Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Virtual Nomad
Moderator
15
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 22nd Mar 2021 03:39
Quote: "i don't suppose a mod could correct the thread title"

done.
[My Itch.io Home] [Now Playing]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]

Login to post a reply

Server time is: 2021-04-10 15:00:28
Your offset time is: 2021-04-10 15:00:28