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 / Tutorial on TYPES and their interrelationship with ARRAYS

Author
Message
Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 24th Jun 2003 17:51
Does anyone know of a good tutorial on how TYPES work in DB Pro and their interrelationship with arrays?

I had a look at Marc Fleury's site (which hasn't been updated since Nov!) but despite a good explanation of Arrays, there is no commentary on TYPEs.

I'm hoping there may be another website that discusses this valuable command somewhere.

Cheers.

Philip
TheCyborg
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 24th Jun 2003 18:38
I think the explanations in the help files is really good...


Not up yet --> http://thecyborg.sytes.net/
Beta1
23
Years of Service
User Offline
Joined: 28th Dec 2002
Location:
Posted: 24th Jun 2003 20:08
Types arent that hard to understand.

Example - storing movement speeds/positions

so this bit sets up an array storing the each objects current speed iin each axis and position



then this bit in your main loop would handle the movement, assuming you had made 10 objects and calculated some accelerations acting on them



So thats one application for you. What you cant currently do is arrays withing types - eg object(L).pos.axis(1)

If you could do that you could simplify the code by for next-ing through the axis.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Jun 2003 20:21
Types are easy enough:



There's currently a bug when assigning one type to another *when in an array* ( 'a(0) = a(1)' ) but I have it on the very best authority that this will be fixed in Patch 5 (ta Lee )
Ian T
23
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 24th Jun 2003 22:48
Good lord IanM you do have an array-- I mean a way of explaining things. Types were a mystery to me up until I looked at that snippit.

--Mouse

Famous Fighting Furball
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 24th Jun 2003 23:07
i've found pointered UDT Variables tends to work most of the time in most cases...

try *a(0)=a(0) - but then my IDE/Compiler have been acting a little weird lately

I pride myself that i don't kill...
well not without a good reason
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 25th Jun 2003 00:07
Quote: "i've found pointered UDT Variables tends to work most of the time in most cases..."


They are not supposed to work, but they do.

Types are pretty simple, just a simple sequence of bytes, where the fields come one after another in memory.

Arrays are much more complicated (ask Ian)

I really hope that arrays in types gets added. How difficult would this be though?

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_103.zip
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Jun 2003 00:31
I've just tried your pointer thing Raven. I either don't understand, or it doesn't work.




Rob, if Lee can deal with strings within UDT's, then technically, there's no reason that he can't also deal with arrays - it's just a more complex version of the same thing.
malcom2073
23
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 25th Jun 2003 05:59
Pointers are kinda hard to understand. Think of it like this. A pointer is like a ruler. You have the word Testing written on a ruler, one letter on each inch mark. T is on the 1 inch mark, e is on the 2 inch mark etc. Say you have a pointer to this ruler, and you set it to three. That pointer is now an s. Same way an array works, except each position is an array position, not a charachter position.

Ian T
23
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 25th Jun 2003 06:36
By the way, 'interrelationships' is a one of the common double-redundants

--Mouse

Famous Fighting Furball
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 25th Jun 2003 09:05
malcome pointers are simple... you just have to remeber that all they are, are an address.

think of eah variable like a warehouse... in each warehouse you simply purchase the entire space you want, how you use it is upto you.
You value pointer will point directly to the address of ths warehuse, and each time you use it the address will go from the base and will load/unload the exact space of the data type at the time.

as the actual use is completely free for the user this means that whateever you wanted to create within them you can.
Infact that is exactly how C/C++'s Structures work ... you'll notice that from this example yu can use them to make arrays in types.



i mean it takes some getting used to, and really could do with the IDE or Compiler setup to do all of this automatically but better than nowt.

I pride myself that i don't kill...
well not without a good reason
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Jun 2003 10:28
Um, I think that I *do* understand pointers, being that I am a C/C++ programmer (7 years), and one of the pioneers of using pointers in DBPro

I just didn't understand what Raven was getting at. I do understand now (with this new example) but now I don't see the point of the extra effort ... but that's a matter of personal preference, and the fact that I have access to an another method
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 25th Jun 2003 11:19
well that ain't how i'd do it if i were to add support to an IDE as its extremely wasteful, and i'd probably recode within a DLL so that i can setup and access them better (plus destorying them automatically on exit)

remember i'm still kind young to the whole pointer system, but it makes sense between the analogy & code

I pride myself that i don't kill...
well not without a good reason
Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 25th Jun 2003 18:53
Yeah ok so leads onto my next question.

Is there any easy explanation of the use of pointers in DB Pro on a website somewhere?

Phil

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Jun 2003 23:12
There is now ... but don't blame me if you find you continually crash your app - this is *unsafe* stuff for your program.


Pointer variables hold a pointer to memory. Because memory is addressed from location 0 upwards, you should ideally hold pointer values within a dword.

Reading a value from an address is done by prefixing the address variable with an asterix ('*').



Writing a value to an address is done in the same way.



You cannot apply pointer arithmetic while also trying to read/set the memory pointed to.



Unlike in C/C++ or Pascal, and most other languages, a pointer holds no information about the size of the memory location it points to. This is up to you, the programmer. The size is based on the variable type that you copy from/to.



Currently, pointers do not work with any types over 4 bytes in size (larger UDTs, arrays, double integers and double floats).

They *do* work with strings, in a quite useful way. When you copy a string to an address, it will give you the location of the string data in memory.



To make memory access easier, I have developed a set of Peek/Poke routines written in DBPro (no external DLL's). It is not possible to do this for getting string addresses, because a copy of the string is made before it is passed to the function, meaning you only get the address of the temporary copy.

I have also included some constants that tell you the size of each type.

WARNING: Do not use the PeekString/PokeString when you have not used SYNC ON. If you do, they will take ages to run.

Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 26th Jun 2003 18:43
Thanks IanM. I will confess that I only understood about 50% of that BUT the 50% I understood was bloody useful.

(Ok, I admit it. I am being thick. Sorry).

Cheers!

Phil

Bloodshot
23
Years of Service
User Offline
Joined: 7th Apr 2003
Location: United Kingdom
Posted: 26th Jun 2003 23:27 Edited at: 26th Jun 2003 23:38
If Philip or anyone else was trying to find out about pointers using the Help Assistant in DBPro, you may find the example text provided confusing, especially as trying to "Print *Ptr" doesn't work:

Replace what you read in the help file:

Quote: "
Ptr as DWORD
Ptr=0x00FF8820
*Ptr=42
PRINT *Ptr

"


with this useable code:



in order to test and use it yourself.

Login to post a reply

Server time is: 2026-07-16 12:18:13
Your offset time is: 2026-07-16 12:18:13