Mirage Source
http://www.miragesource.net/forums/

Size Variables
http://www.miragesource.net/forums/viewtopic.php?f=210&t=1364
Page 1 of 2

Author:  Bakekitsune [ Thu Feb 15, 2007 10:38 pm ]
Post subject:  Size Variables

I will start off with a question... How many of you believe that you are going to have more than 32,000 players on one server.

1. Change all "byval index as long" to "index as integer" which should half the memory consumption for all that.

2. Change lcase(parse(0)) = "
to case

3. In type recs or even anywhere unless you are going to have more than 32,000 of something change from long to integer which will have the amount of memory it takes up.

4. Change all booleans to byte and use 0 and 1
5. Even better if you use the bitfield system (just search it) *props

6. If you are always going to get a value between 255 and 0 then change longs or integers to byte. that should decrease that memory consumption by down to 1/8th

7. Don't use fixed length strings e.g "* MAX_LENGTH" just remove it you dont need it. if you want a max character property change that in the textbox properties.

8. if you use exit sub anywhere its easier just to use select case.

I no theres more but i forget lol :P

Author:  William [ Thu Feb 15, 2007 11:29 pm ]
Post subject: 

Moved to Knowledge base.

Quote:
1. Change all "byval index as long" to "index as integer" which should half the memory consumption for all that.

Change it to Byte instead.

Quote:
2. Change lcase(parse(0)) = "
to case

It has proven that no speed change occur.

Quote:
3. In type recs or even anywhere unless you are going to have more than 32,000 of something change from long to integer which will have the amount of memory it takes up.

Nothing in MS requires anything to be above 32000. So not sure if that is a good idea.

Quote:
4. Change all booleans to byte and use 0 and 1

Yes, thats good. There are already a constant for that I think.. YES and NO?

Quote:
5. Even better if you use the bitfield system (just search it) *props

Hum?

Quote:
6. If you are always going to get a value between 255 and 0 then change longs or integers to byte. that should decrease that memory consumption by down to 1/8th

Isn't the difference between byte and long 2bytes or something?

Code:
7. Don't use fixed length strings e.g "* MAX_LENGTH" just remove it you dont need it. if you want a max character property change that in the textbox properties.

Yeah, that would work.

Quote:
8. if you use exit sub anywhere its easier just to use select case.

hum?

Author:  Spodi [ Thu Feb 15, 2007 11:37 pm ]
Post subject: 

These are all not bad ideas, but you have to think on a wider scope. For 1, yes, you save 3 bytes if you convert it to a byte for every player on. Overall, that will save you, what? 150 bytes on a decently populated server (50 people on)? Its not bad to do this - in fact, its very good practice, but unless it is very critical (such as a loop called 100 times a second, or an array with over 1000 elements), you can spend months doing all little kinds of optimizations and end up with no noticeable difference.

8. Not really - each has their own use. Select case works only if comparing one variable.

Author:  William [ Thu Feb 15, 2007 11:45 pm ]
Post subject: 

1byte = nothing
1000 byte = 1kb
1000 kb = 1mb

You see the point ;) But as everyone says, MS needs all improvements it can get.

Author:  Obsidian [ Thu Feb 15, 2007 11:47 pm ]
Post subject: 

All of the things mentioned have been mentioned before pretty much... and/or are common sense to most people (i would hope)... in all honesty i really don't think it matters too much anymore how much you try to optimize mirage. Sooner or later... about 90% of the way the server manages stuff is going to have to be rewritten...

[Edit]
And just to point it out... because that's how i roll...

8 Bits = 1 Byte
1024 Bytes = 1 KB... it's not 1000 like most people think...

Author:  William [ Thu Feb 15, 2007 11:52 pm ]
Post subject: 

Ahh.. thats why all computer has 128RAM... 1024RAM etc ;)

Author:  Spodi [ Thu Feb 15, 2007 11:54 pm ]
Post subject: 

It actually depends on what you are using for the measurement. The golden rule of 1024s is technically correct, but I think hosting companies often round down and call it 1000byte = 1kb, etc. I have seen in done in other cases, too. Its not that they are trying to scam you out of your money, its just the way they do it (probably started for saving money, though :wink: ).

Author:  Lea [ Fri Feb 16, 2007 5:42 am ]
Post subject: 

Quote:
7. Don't use fixed length strings e.g "* MAX_LENGTH" just remove it you dont need it. if you want a max character property change that in the textbox properties.

Yeah, that would work.


If you don't make a string fixed length, it uses 20 bytes + the string length MORE memory. Keep all the strings that you can fixed length.

Author:  Bakekitsune [ Fri Feb 16, 2007 8:53 am ]
Post subject: 

Dear william i will answer all you questions... plus more

Quote:
Change it to Byte instead


Seeing as byte only goes up to 255 that would mean you could have only up to 255 players... hence integer which goes up to around 32000


Quote:
It has proven that no speed change occur.


In a very large procedure like "handledata" it does make a difference and you can also save alot of space (text wise) because you can remove "if" "lcase parse" "then" and "exit sub"

Quote:
Nothing in MS requires anything to be above 32000. So not sure if that is a good idea




thats my point change all longs to integer lol

Quote:
Hum?


Bitfield in mirage was devised by someone i think it was dave not sure, which fits 8 booleans in a byte.

Quote:
Isn't the difference between byte and long 2bytes or something?


No in vb6, byte = 1 long = 8

Quote:
If you don't make a string fixed length, it uses 20 bytes + the string length MORE memory. Keep all the strings that you can fixed length.
Actually fixed length strings cause problems


Yes you would be right if everyone were to fill in all the spaces but...

Fixed-length strings are generally slower than conventional strings, because all VB string functions and operators only recognize conventional strings, thus all fixed-length strings must be transparently converted to and from conventional strings.

Author:  William [ Fri Feb 16, 2007 9:45 am ]
Post subject: 

Not sure how long you have been in the community, and I don't think anybody know how many players a optimized MSE can carry. But I doubt it will go above 255 at the same time.

Author:  Bakekitsune [ Fri Feb 16, 2007 10:14 am ]
Post subject: 

ive been here since i was 12-13 so 4-5 years ago btw no offense (this is in no means offensive in anyway) but there is already a game called key2heaven (just letting you know :P)

perhaps unless you have a friend with t3 and im getting ADSL2 anyway...

Im also devising a new mix client/server system which could handle unlimited players (with the expense of easy hacking if found out. :P)

Author:  William [ Fri Feb 16, 2007 10:21 am ]
Post subject: 

I didn't know there was such a game. Would you like to link me?

Edit: Just searched, found a game name Key of Heaven. =/

Author:  Verrigan [ Fri Feb 16, 2007 6:31 pm ]
Post subject: 

Bakekitsune wrote:
Quote:
Isn't the difference between byte and long 2bytes or something?


No in vb6, byte = 1 long = 8

Uh... Last I checked, a Byte = 1 byte in length, and a Long = 4 bytes in length.
Bakekitsune wrote:
Quote:
If you don't make a string fixed length, it uses 20 bytes + the string length MORE memory. Keep all the strings that you can fixed length.
Actually fixed length strings cause problems


Yes you would be right if everyone were to fill in all the spaces but...

Fixed-length strings are generally slower than conventional strings, because all VB string functions and operators only recognize conventional strings, thus all fixed-length strings must be transparently converted to and from conventional strings.

Do you write articles for DevX.com? http://www.devx.com/vb2themax/Tip/18269

[edit]
I should also mention that this is a false statement. Fixed-length strings are not slower than conventional (variable-length) strings. Why? When you change the value of a variable length string, it may have to have its memory reallocated. That means.. If you are appending data to a variable-length string, it may have to have a new memory pointer assigned to it that has enough memory to accomodate the larger size.. Then, the original value has to be copied to that new location, and the additional data added to the end.. Imagine a loop that does something like this:
Code:
'Note: This is not a feasible way of handling data.. but the concept still applies.
StoredStr = ""
For i = 1 To Len(DataStr)
  StoredStr = StoredStr & Left(DataStr, 1)
  DataStr = Right(DataStr, Len(DataStr) - 1)
Next

The string is initialized as "" (0-length)
Then, let's say that memory location has 10 available bytes, but that DataStr is actually 20 characters long.. Since VB stores strings as unicode, you can only store 5 characters in the stored string prior to it having to be moved to a new location.. Then, it might use the next available spot of memory that has enough to handle 1 extra character.. Which means it will be moved again and again until the entire string from DataStr is in StoredStr.

Fixed Length strings are assigned a place in memory, and never have to change that memory location because the size of the string is fixed, and so is the memory that is allocated to it.

Morale of the story... Don't believe everything you read on the internet. :)

Author:  Spodi [ Fri Feb 16, 2007 10:56 pm ]
Post subject: 

Variable and fixed length both have their times and uses. You shouldn't just use one because it is better or whatever - if you are even doing string-intensive operations in a 2d ORPG (or most any online game non-text based) you have seriously screwed up already. Using a variable-length string is probably going to be faster then using Trim$(CosntantString). If you know a string will be X characters long, and never anything else, then go ahead and use that.

Author:  Verrigan [ Fri Feb 16, 2007 10:59 pm ]
Post subject: 

Good advice. :)

Author:  Lea [ Sat Feb 17, 2007 1:53 am ]
Post subject: 

I also believe we prooved a while back that integers are slower than longs in some situations. Moral of the story: Depending on what that variable is doing, Long may be a better option even if it is too big.

Author:  Verrigan [ Sat Feb 17, 2007 3:24 am ]
Post subject: 

Dave wrote:
I also believe we prooved a while back that integers are slower than longs in some situations. Moral of the story: Depending on what that variable is doing, Long may be a better option even if it is too big.

I made a Speed test application a while back... I just ran it again on my new laptop.. Here are the results:

Optimizations included will be shown in bold.
Native, Fast Code (All Advanced + P-Pro)
Byte Loop Average: 0.0048 seconds.
Integer Loop Average: 0.0061 seconds.
Long Loop Average: 0.0061 seconds.
Single Loop Average: 0.0095 seconds.
Double Loop Average: 0.0063 seconds.
Currency Loop Average: 0.2812 seconds.
Variant Loop Average: 0.6282 seconds.

Native, Fast Code (All Advanced)
Byte Loop Average: 0.003 seconds.
Integer Loop Average: 0.0092 seconds.
Long Loop Average: 0.0047 seconds.
Single Loop Average: 0.0094 seconds.
Double Loop Average: 0.0063 seconds.
Currency Loop Average: 0.2813 seconds.
Variant Loop Average: 0.614 seconds.

Native, Fast Code (P-Pro)
Byte Loop Average: 0.0422 seconds.
Integer Loop Average: 0.0281 seconds.
Long Loop Average: 0.0204 seconds.
Single Loop Average: 0.0499 seconds.
Double Loop Average: 0.0704 seconds.
Currency Loop Average: 0.375 seconds.
Variant Loop Average: 0.6187 seconds.

Native, Fast Code
Byte Loop Average: 0.0391 seconds.
Integer Loop Average: 0.0281 seconds.
Long Loop Average: 0.0187 seconds.
Single Loop Average: 0.0468 seconds.
Double Loop Average: 0.0721 seconds.
Currency Loop Average: 0.3609 seconds.
Variant Loop Average: 0.6076 seconds.

Native, No Optimizations
Byte Loop Average: 0.0545 seconds.
Integer Loop Average: 0.0344 seconds.
Long Loop Average: 0.0171 seconds.
Single Loop Average: 0.0562 seconds.
Double Loop Average: 0.0672 seconds.
Currency Loop Average: 0.3516 seconds.
Variant Loop Average: 0.7014 seconds.

Native, Small Code
Byte Loop Average: 0.0362 seconds.
Integer Loop Average: 0.0299 seconds.
Long Loop Average: 0.0185 seconds.
Single Loop Average: 0.0469 seconds.
Double Loop Average: 0.0734 seconds.
Currency Loop Average: 0.3627 seconds.
Variant Loop Average: 0.7 seconds.

P-Code
Byte Loop Average: 0.736 seconds.
Integer Loop Average: 0.4047 seconds.
Long Loop Average: 0.4015 seconds.
Single Loop Average: 0.422 seconds.
Double Loop Average: 0.4359 seconds.
Currency Loop Average: 0.5984 seconds.
Variant Loop Average: 1.3734 seconds.

VB IDE
Byte Loop Average: 0.8047 seconds.
Integer Loop Average: 0.4548 seconds.
Long Loop Average: 0.4547 seconds.
Single Loop Average: 0.4906 seconds.
Double Loop Average: 0.4876 seconds.
Currency Loop Average: 0.6658 seconds.
Variant Loop Average: 1.4888 seconds.

The code for the above tests was 10 loops of the following:
Code:
  lStart = GetTickCount
  For Variable0 = 0 To 254
    For Variable1 = 0 To Variable0
      For Variable2 = 0 To Variable1
        VariableR = Variable0 * 100 - Variable0 * 100 + _
                 Variable1 * 100 - Variable1 * 100 + _
                 Variable2
      Next
    Next
  Next
  lStop = GetTickCount

The variables (except for lStart and lStop) were all declared separately (vData# As Variant, lData# as Long, etc.) for each 'type' loop. I had each of these loops run 10 times, and you are seeing the average time for each loop to complete.

I'm pretty sure Spodi has made a tool that tests the different data types, as well.

But as you can see.. In all cases, Longs were faster than Integers, except for Native, Fast Code (All Advanced + P-Pro). On another note, with all advanced optimizations, the Byte data type seems to be faster than all others. :)

Author:  Bakekitsune [ Sat Feb 17, 2007 5:10 am ]
Post subject: 

lol im confused... how can a 2byte datatype be slower than a 4byte data type

thx anyway thats awesome coz all of my datatypes are byte so i just have to click all advanced options, what do you recommend i dont click?

also yeh i got confused wit vb.net

VB6
16bits/2 bytes for integer
32bits/4 bytes for long

VB.NET
16bits/2 bytes for short
32bits/4 bytes for integer
64bits/8 bytes for long

Author:  Verrigan [ Sat Feb 17, 2007 5:13 am ]
Post subject: 

I recommend using Native with all advanced optimizations without the Pentium Pro optimizations..

P-Code seems to be almost as slow as the IDE.. Haven't ever needed it, though...

Author:  Bakekitsune [ Sun Feb 18, 2007 12:53 am ]
Post subject: 

awesome thanks!

Author:  Shannara [ Thu Feb 22, 2007 11:46 pm ]
Post subject: 

Because, longs are 32-bit numbers in VB6, while Integers are 16-bit. Since most processors now days are 32-bit, they can handle Longs much faster then integers.

However, if your running a 64-bit processor, then Quads are faster then Longs. Unfortunately, VB6 have no 64-bit integers ... :(

Author:  Spodi [ Fri Feb 23, 2007 12:19 am ]
Post subject: 

Double and Currency. :wink:

Author:  Shannara [ Fri Feb 23, 2007 12:34 am ]
Post subject: 

Double: not enough precision
Currency: can't handle the maximum 64-bit values

Refs:

http://www.thescripts.com/forum/thread15354.html
http://www.experts-exchange.com/Program ... d=21579668
http://www.devx.com/vb2themax/Tip/18308
http://en.wikipedia.org/wiki/Visual_Basic

Author:  Spodi [ Fri Feb 23, 2007 2:24 am ]
Post subject: 

Quote:
However, Visual Basic does provide an unusual "Currency" Data Type, which is essentially a 64-bit fixed-point number with 15 digits to the left and 4 to the right of the decimal point.


Tell me how that is not 64-bit, even if it is fixed point. :wink:

Author:  wanai [ Thu Dec 16, 2021 5:42 am ]
Post subject:  Re: Size Variables

audiobookkeeper.rucottagenet.rueyesvision.rueyesvisions.comfactoringfee.rufilmzones.rugadwall.rugaffertape.rugageboard.rugagrule.rugallduct.rugalvanometric.rugangforeman.rugangwayplatform.rugarbagechute.rugardeningleave.rugascautery.rugashbucket.rugasreturn.rugatedsweep.rugaugemodel.rugaussianfilter.rugearpitchdiameter.ru
geartreating.rugeneralizedanalysis.rugeneralprovisions.rugeophysicalprobe.rugeriatricnurse.rugetintoaflap.rugetthebounce.ruhabeascorpus.ruhabituate.ruhackedbolt.ruhackworker.ruhadronicannihilation.ruhaemagglutinin.ruhailsquall.ruhairysphere.ruhalforderfringe.ruhalfsiblings.ruhallofresidence.ruhaltstate.ruhandcoding.ruhandportedhead.ruhandradar.ruhandsfreetelephone.ru
hangonpart.ruhaphazardwinding.ruhardalloyteeth.ruhardasiron.ruhardenedconcrete.ruharmonicinteraction.ruhartlaubgoose.ruhatchholddown.ruhaveafinetime.ruhazardousatmosphere.ruheadregulator.ruheartofgold.ruheatageingresistance.ruheatinggas.ruheavydutymetalcutting.rujacketedwall.rujapanesecedar.rujibtypecrane.rujobabandonment.rujobstress.rujogformation.rujointcapsule.rujointsealingmaterial.ru
journallubricator.rujuicecatcher.rujunctionofchannels.rujusticiablehomicide.rujuxtapositiontwin.rukaposidisease.rukeepagoodoffing.rukeepsmthinhand.rukentishglory.rukerbweight.rukerrrotation.rukeymanassurance.rukeyserum.rukickplate.rukillthefattedcalf.rukilowattsecond.rukingweakfish.rukinozones.rukleinbottle.rukneejoint.ruknifesethouse.ruknockonatom.ruknowledgestate.ru
kondoferromagnet.rulabeledgraph.rulaborracket.rulabourearnings.rulabourleasing.rulaburnumtree.rulacingcourse.rulacrimalpoint.rulactogenicfactor.rulacunarycoefficient.ruladletreatediron.rulaggingload.rulaissezaller.rulambdatransition.rulaminatedmaterial.rulammasshoot.rulamphouse.rulancecorporal.rulancingdie.rulandingdoor.rulandmarksensor.rulandreform.rulanduseratio.ru
languagelaboratory.rulargeheart.rulasercalibration.rulaserlens.rulaserpulse.rulaterevent.rulatrinesergeant.rulayabout.ruleadcoating.ruleadingfirm.rulearningcurve.ruleaveword.rumachinesensible.rumagneticequator.rumagnetotelluricfield.rumailinghouse.rumajorconcern.rumammasdarling.rumanagerialstaff.rumanipulatinghand.rumanualchoke.rumedinfobooks.rump3lists.ru
nameresolution.runaphtheneseries.runarrowmouthed.runationalcensus.runaturalfunctor.runavelseed.runeatplaster.runecroticcaries.runegativefibration.runeighbouringrights.ruobjectmodule.ruobservationballoon.ruobstructivepatent.ruoceanmining.ruoctupolephonon.ruofflinesystem.ruoffsetholder.ruolibanumresinoid.ruonesticket.rupackedspheres.rupagingterminal.rupalatinebones.rupalmberry.ru
papercoating.ruparaconvexgroup.ruparasolmonoplane.ruparkingbrake.rupartfamily.rupartialmajorant.ruquadrupleworm.ruqualitybooster.ruquasimoney.ruquenchedspark.ruquodrecuperet.rurabbetledge.ruradialchaser.ruradiationestimator.rurailwaybridge.rurandomcoloration.rurapidgrowth.rurattlesnakemaster.rureachthroughregion.rureadingmagnifier.rurearchain.rurecessioncone.rurecordedassignment.ru
rectifiersubstation.ruredemptionvalue.rureducingflange.rureferenceantigen.ruregeneratedprotein.rureinvestmentplan.rusafedrilling.rusagprofile.rusalestypelease.rusamplinginterval.rusatellitehydrology.ruscarcecommodity.ruscrapermat.ruscrewingunit.ruseawaterpump.rusecondaryblock.rusecularclergy.ruseismicefficiency.ruselectivediffuser.ruсайтsemifinishmachining.ruspicetrade.ruspysale.ru
stungun.rutacticaldiameter.rutailstockcenter.rutamecurve.rutapecorrection.rutappingchuck.rutaskreasoningtechnicalgrade.rutelangiectaticlipoma.rutelescopicdamper.ruhttp://temperateclimate.rutemperedmeasure.rutenementbuilding.rutuchkasultramaficrock.ruultraviolettesting.ru

Page 1 of 2 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/