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
User Banned
Posted: 15th Mar 2021 14:09 Edited at: 11th Jun 2021 21:23
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.]


[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]



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

Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others

Attachments

Login to view attachments
Bored of the Rings
User Banned
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
User Banned
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
User Banned
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
User Banned
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
User Banned
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
User Banned
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
User Banned
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
18
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]
Bored of the Rings
User Banned
Posted: 12th Apr 2021 11:15
still working on this on and off, other projects ongoing at the moment.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
User Banned
Posted: 6th Jun 2021 20:30
more updates to come this week, working on this currently.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
User Banned
Posted: 11th Jun 2021 21:25
see updates on first post.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
User Banned
Posted: 12th Nov 2021 20:28 Edited at: 12th Nov 2021 20:52
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.

Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
User Banned
Posted: 16th Nov 2021 21:06
new update to come soon as the last version not 100% correct.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
User Banned
Posted: 19th Nov 2021 06:36 Edited at: 19th Nov 2021 06:46
update - only uses alloc for now - need to add code again for memblock, bank or you guys could have a go.

Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
User Banned
Posted: 19th Nov 2021 07:05 Edited at: 19th Nov 2021 07:05
added MakeFileFromMemory function. This is fast. more to come.

Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Bored of the Rings
User Banned
Posted: 6th Mar 2022 06: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.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others

Login to post a reply

Server time is: 2024-04-19 11:17:17
Your offset time is: 2024-04-19 11:17:17