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 / Can you do this with UDT

Author
Message
Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 10th Sep 2003 07:54
Type Simple
Easy AS INTEGER
Nice AS STRING
EndType

Type Complex
Hard AS INTEGER
Inpossible AS STRING
EndType

Dim Stuff(2)
Stuff(1) AS Simple
Stuff(1).Easy=50
Stuff(1).Nice="Nice"
Stuff(2) AS Complex
Stuff(2).Hard=528
Stuff(2).Impossible="Impossible"

Basically, this is what I want to do. The Question is, is DBPro cabable of defining seperate elements within an array to their own UDT's, instead of declaring an entire array as on UDT. If not, there need be no worry on my part concerning it, for I have already found a more complex way of solving my problem, but if I were capable of doing it this way, it would be so much simpler. Thank you for your time.

Regards,
Ryan Wilson
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 10th Sep 2003 12:00 Edited at: 10th Sep 2003 12:01
No, that doesn't work and quite reasonably too - a dim on its own like that defines an integer type, and you would be trying to define something thats already defined.

You might find Linked Lists useful...


Avatar & Logo by Indi. Come to the UK DBPro Convention in Chichester
Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 10th Sep 2003 17:04
Eh, sorry about not replying last night, I accidently feel asleep. Could you tell me what a linked list is? I don't beleive I saw any mention of them in the help files, and thus you have stoked my curiousity.
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 10th Sep 2003 17:21
In DBPro parlance, its Lists, Stacks and Queues, and its documented.

Essentially they are a way of store data in such a way that you dont waste memory storing anything you dont need - you use only what you add to the linklist. The name is determined by how the data is stored.

Eg if you dim a(1000), your allocation 1000*4 bytes, so if your only storing one item, you've wasted 3996 bytes.

If you use a linklist, you could use 4 bytes (for the data), 4 bytes to point to the next record, giving a total of 8, thereby saving 3988 bytes.


Avatar & Logo by Indi. Come to the UK DBPro Convention in Chichester
Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 10th Sep 2003 17:24
Ah, the list. I will admit, I had been curious about those. Alright, I'll start looking at those. Thanks again,TCA!
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 10th Sep 2003 18:59
Thats okay.


Avatar & Logo by Indi. Come to the UK DBPro Convention in Chichester
Dreamora
23
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Switzerland
Posted: 10th Sep 2003 20:11 Edited at: 10th Sep 2003 20:13
to the questions
you can make 2 "arrays"
dim simples(1) as simple
dim complex(1) as complex

and every new object add at the top of this or bottom through the right commands
this is better anyway since you wouldn't be able to read out any datas otherwise because you don't know which type of data would be at this index position


and how do I implement binary trees and things like that in DBP since it's not capable of real pointers and


TYPE node
last as node
next as node
value as integer
datas as dword
ENDTYPE

will give a bad bug because DBP tries to solve the last/next instead of having any abilities as there would be needed to make real UDTs?
I'm quite a bit annoyed of writting C++ / PB plugins just to have what any nearly up-to-date language is able to perform without any problems
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 10th Sep 2003 20:29
I've got a linklist plug-in that should let you do binary trees - it'll be hard, but possible.


Avatar & Logo by Indi. Come to the UK DBPro Convention in Chichester
Dreamora
23
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Switzerland
Posted: 10th Sep 2003 22:08
it would be possible if you could use arrays / linlists in types, but even this is impossible, think due to the same reason why there is no real pointer

before i try some strange plugin i make it directly with C++ or PB and use memblocks for datastransfers ...
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 10th Sep 2003 23:01
Quote: "it would be possible if you could use arrays / linlists in types"

You just need to store memory addresses...

Quote: "strange plugin"

charming...


Avatar & Logo by Indi. Come to the UK DBPro Convention in Chichester
Dreamora
23
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Switzerland
Posted: 11th Sep 2003 03:00
yeah you just need to store memory adresses but types don't have memory adresses
and using memblocks to hold numberless variables is quite annoying and doesn't make the code clearer. and memblocks aren't that fast too, so I would prefer real pointers for cases like this.
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 11th Sep 2003 11:00
Thats why my linklist plug-in will come in useful, it uses and returns memory addresses.

And actually if you DIM a TYPE, you can get its address.


Avatar & Logo by Indi. Come to the UK DBPro Convention in Chichester

Login to post a reply

Server time is: 2026-07-25 08:12:36
Your offset time is: 2026-07-25 08:12:36