Errors, bugs, questions - page 1648

 
Alexey Navoykov:
Isn't that how the current 0 works?
 
Комбинатор:
Isn't that how the current 0 works?

In general, there is a lot of confusion there, we can't know the real size of the allocated memory for the array to check it and optimize it.

 
Or let's say the following case. First ArrayResize(arr, 10, 100); Then ArrayCopy(arr, arr2, 0, 0, 20); Will the size of the reserved memory for the array be reduced?
 
Alexey Navoykov:

If I remember the explanation correctly, the reserve size will not decrease even if it is explicitly given a smaller number.

Wrong. Judging from the help example, 0 does indeed work as 0 and then the -1 suggestion makes a lot of sense.

 
By the way, my reasoning about reserve_size is not quite correct. In fact, it is just a step of reserve change, but not reserve itself. That is, it probably is not stored anywhere. But the total size of allocated memory is known. We would like to know it somehow, and ideally manage it directly.

And I will rephrase my suggestion about ArrayResize as follows: when specifying reserve_size=-1, the function must not change the memory size allocated for the array if the size parameter lies within this range. If size > capacity, the buffer will grow of course.
 
The array ("inside") stores how many elements the array is allocated to.

The logic for working with allocated (conditional code):
ArrayResize(arr,int size,int reserve)
  {
   if(arr.allocated<size)
      if(!ArrayAllocateMemory(arr,size+reserve))  // -> arr.allocated=size+reserve;
         return(-1);
   //---
   CallConstructorsOrDestructors(arr,size);
   //---
   arr.size=size;
   return(size);
  }
 
Ilyas:
The array ("inside") stores how many elements the array is allocated to.

The logic of working with allocated (conditional code):

I see, thank you. And in the beginning this allocated is equal to -1, or not? I.e. at initial call of ArrayResize(arr, 0, 100) allocation will be?

 
Alexey Navoykov:

Is this allocated at the beginning equal to -1, or not?

Equals 0
Alexey Navoykov:

I.e. when ArrayResize(arr, 0, 100) is called initially, will allocation occur?

The allocation only happens if the size of the array changes upwards. In this case, the size of the array doesn't change, because it was equal to 0.

 
FVitalii Ananev:
The difference is that in the first case there is no error :)
And why is there no error in C2C++ in both cases? (See above for the answer to what C2C++ has to do with it)
 
How do I remove a URL from the trusted list? The help text says:"To delete an address from the trusted list, select it and press "Delete" button", but there is no such button.
Reason: