Quote:
Originally Posted by SunB
... there were 2 problems with my code.
1. the address that I added to opcode were not converted to hex
|
Why would anything need to be converted?
Hex or decimal, it's just presented to you in that way, in memory it's the same value. Unless you are storing it in a string ...
Quote:
Originally Posted by SunB
2. create byte[] in C# is a little tricky when you want to build the same structure as Autoit code :D
|
Why would you even bother building same structure as AutoIt code in C#?
Defeats the purpose of using C# if you are going to code with same approach as AutoIt. You are better of using AutoIt then, are you not?
Quote:
Originally Posted by SunB
...The reason I did not put the opcode directly to byte[] is that you need to extend your byte[] when you need to add more opcode, string is still a good choice :D
|
Dynamic byte[] array you need to resize manually, string resizes automatically.
In both cases same thing happens, useless memory copying. Memory copying is one of the biggest resource drains you can put on a computer, so smart money is on avoiding that if and when possible.
How about static byte[] array?
Check what approximate maximum size sent packet can be and set it to that length from start.
Largest packet by far, I can think of (check player trade too, to be sure), is trading with NPC. Selling maximum amount of items (12) and buying maximum amount of items (12) at the same time.
Each item's structure is made up of 12 bytes, that brings you to 288 bytes. Adding to this preceding data in sell/buy packet, 18 bytes I think, and you've got max size = 306 bytes. Round it up to 512, just to be on the safe side if you are prone to panic and bob's your uncle.
Surely 512 bytes of memory is a better price to pay than constant load on CPU to reallocate and copy array data on every resize, which is what you have now.
Well ok, 512 + 4 bytes, you will need that to track current size of it, but still.
And don't allocate that array every time you need to sent a packet or you again gained nothing.
Do it once and reuse it when needed. Don't bother clearing it, you are overwriting bytes you use, keep separate variable for count and you only read count number of bytes. What the rest of array holds from previous uses is not important.
Be sure to clean it up however, like when terminating bot.