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.

Newcomers DBPro Corner / Having multiple large UDT's

Author
Message
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 10th May 2007 14:05
I was just wondering, does having multiple and large UDTs slow a game down? If so I'll try to avoid it. When I say a large UDT I mean a UDT with 50-100 different things in it (not that I've done that yet). Is having a UDT that large a bad idea?

Thanks,
-Sixty Squares

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th May 2007 15:34
I believe that once compiled, it makes no difference. It's a design thing rather than a runtime consideration.

Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 11th May 2007 01:00
Thanks BatVink.

Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 11th May 2007 01:06
What does UDT stand for?

Further on my stuff at...
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 11th May 2007 01:56
User Defined Type.

EX:


TYPE Person
Health as integer
Damage as integer
Mana as integer
ENDTYPE

global Player as Person


Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 11th May 2007 02:37
It does matter if passing it to a function, since all the data needs to be copied over in the process.

Who needs a signature?
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 11th May 2007 18:30
Milk, wouldnt that only be if you passed the entire variable over using something like a pointer? If you just pass one entry of the UDT into a function, I dont see it getting the entire UDT, just grabbing the value of the entry specified.

Maybe Im wrong...just seems passing the entire variable wouldn't make much sense.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th May 2007 19:16
Quote: "It does matter if passing it to a function, since all the data needs to be copied over in the process"


But the alternative would be to specify all values, achieving the same goal but with messier code.

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 11th May 2007 19:25
It depends how DBP handles types. If it simply passes a pointer, then there will be no speed loss.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 13th May 2007 15:28
Thanks all. Hopefully I won't lose too much loading time due to massive types.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th May 2007 09:01
Quote: "If it simply passes a pointer, then there will be no speed loss."


I'm pretty sure thats what it does.


Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 15th May 2007 20:20
If it does that why does it not treat it like a regular variable? If it does treat it like a variable, why can't it handle arrays too?

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th May 2007 15:16 Edited at: 16th May 2007 15:19
Quote: "If it does treat it like a variable, why can't it handle arrays too?"


Consider this:



Now you have an array of a type containing an array of another type, which itself contains another array. It's only 2 types and syntactically, you would be allowed to write this. But do you want the job of writing the parser to work that mess out?

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 16th May 2007 17:56
It wouldn't be much of a parser job. Once you can point to the memory location of an array, then you just have to treat it usually.

For your example, you could do MyArray(3).var2(MyArray(8).var1).angle(3)

You:

Get MyArray's location + 3*sizeof(MyType)
Get MyArray's location + 8*sizeof(MyType)
Get the location of var1
Add the data in that location to the register
Get location of var2 (from the first operation) + register value*sizeof(Coords)
Get location of angle + 3*sizeof(float)
Get the value at that location

That's ust worked out on the spot. I don't know if it would be buggy, but it is possible (and this is from a kid who has had no real training on compilers). I don't think it would have been too much extra work, but it would have made a huge difference.

I think their problem is that they just dont treat arrays like they should. I think they are more like linked lists, and that would make it harder to work.

Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 16th May 2007 22:59
Quote: "Get MyArray's location + 3*sizeof(MyType)"


Well, remember sizeof is filled in at compile time and since 3 is a constant it would probably be optimized into MyArray's location + 12 (assuming 32ints)

More specifically, it would look like this:



But I've never coded a compiler either so I could be wrong (I never even wrote an assembly program before, this is just a guess)

Beyond this place there be dragons.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 16th May 2007 23:05
Yup, I was just doing it in pseudo-code. Not sure what size MyType would be either heh. Just depends how DB handles it I think. Also, I believe DB has no optimisation.

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 19th May 2007 11:15 Edited at: 19th May 2007 13:38
<Note to self: don't speak to soon.>

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 19th May 2007 13:34
Quote: "each array you declare is created at runtime"


Hmm, never knew that. I'm guessing that's not the same for all languages right?

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 19th May 2007 13:36 Edited at: 19th May 2007 13:39
Actually, after doing a little more testing I feel I might just be wrong.. I'm not sure, I'll have to continue experimenting.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)

Login to post a reply

Server time is: 2024-11-25 17:41:39
Your offset time is: 2024-11-25 17:41:39