Algorithms, solution methods, comparison of their performance - page 7

 
Alexandr Andreev:

well, in a nutshell, a string of one character is achar with some code from 0 to 255 and weighs 1 byte... and it's allocated just enough memory to have 256 values, 257 won't fit there, it will switch back to the first one.

In any page, every character is a number from 0 to 255... so we take the number 10000000 - it weighs 4 bytes, convert it to the string "10000000" then for each character we allocate memory as for a individual chart from 0 to 255... 8 bytes total. There's no memory saving anywhere.

I see what you mean.

We need to accurately calculate memory consumption for this solution.

 
Реter Konow:

You can start writing the second line. Then the third and so on... :)

Now I understand why it takes so long to create your "constructor".
 
Vasiliy Sokolov:


p.s. Oh yes, you have one more error. If MathRand on the third call returns e.g. number 1000 and writes _3_1000_, what kind of medge will be found for a transaction with order number 1000?

The point is that MathRand is only needed to simulate medigee numbers.

Medjic numbers are set by the user, and it can bypass a value less than 100,000 (let's say).

However, there may be an error within the example given. You are correct.

Thanks for the observation. A complete solution should take this into account.

 
Реter Konow:

I see your point.

We need to accurately calculate the amount of memory consumed by this solution.


This also wastes a lot of resources on internal references, because access to each string character is the same as access to char[x] array. A link in this case is access to a certain array element. And you'll just go through huge piles of them there. Implementation with int would be many times easier and quicker to understand...

As for string length limitation, it usually depends on the maximum size limit in char[x] array - it has its own maximum limit as well.

 

The man genuinely does not realise the extent of his own stupidity.
The Dunning-Kruger effect in action.

 

It's ok, a person just needs a non-typed language and no problems))

although there will still be a difference in speed
 
Vasiliy Sokolov:
p.s. Oh yes, you have one more error. If MathRand on third call returns for example number 1000 and write _3_1000_, what magik will be found for deal with ordinal number 1000?
It will "think" a bit more and solve this problem: put an underscore before the deal, and another symbol before the magician :)
 
Alexandr Andreev:

This also wastes a lot of resources on internal references, because accessing each string character is the same as accessing char[x] of an array. A link in this case is access to a certain array element. And you'll just go through huge piles of them there. Implementation with int would be many times easier and quicker to understand...

As for string length limitation, it usually depends on maximum size limitation in char[x] array - it has its own maximum limit, as well as others.

We can't implement it with int, because we don't know in advance the number of future transactions. We either have to guess or change the size of the array on each trade and rewrite the data back and forth.

How else do we do it?

The speed of my solution is insane.

Memory is consumed, but it's unknown how inefficient. We need to find out for sure.

 
Yury Kulikov:
He will "think" a bit more and solve this problem: he will put an underscore before the transaction, and a different symbol before the magician :)

I would like to point out that, unlike everyone else here, Peter probably has the greatest patience - and a willingness to write monotonous code. Otherwise I cannot explain how he managed to write so many things

 
Реter Konow:

We cannot implement with int, because we do not know in advance the number of future trades. We either have to guess, or we have to change the size of the array and overwrite the data back and forth on each trade.

How else do we do it?

The speed of my solution is insane.

Memory is consumed, but it's unknown how inefficient. We need to find out for sure.


There are only two variants of string either it has a maximal size (in reserve), or also the memory is allocated and in your case during the addition process it is allocated every time.... So, it is the same as changing the size of an int array. 1in1 well maybe it takes 10% longer for int to allocate memory than for string to allocate memory for 1 character, if you compare more characters then i guess int wins

Reason: