Всем привет!
Rus: Допустим, мы имеем массив из Byte (n: array[1..20] of Byte). Когда я хочу его обнулить
Eng (yandex translate): Let's say we have an array of Byte (n: array[1..20] of Byte). When I want to reset it
for i := 1 to 20 do
n[i] := 0;
Rus: мы получаем (ассемблер x86):
Eng: we get (x86 assembler):
movb $0x0,(%rsp)
movb $0x0,0x1(%rsp)
movb $0x0,0x2(%rsp)
...
movb $0x0,0x13(%rsp)
Rus: понимаем, что в 32-х/64-х битных системах, это не очень хороший подход.
Добавляю в код переменную-указатель (Pn: PLongWord), меняю код в паскале
Eng: we understand that in 32-bit / 64-bit systems, this is not a very good approach.
I add a pointer variable (Pn: PLongWord) to the code, I change the code in pascal
Pn := @n;
for i := 0 to 4 do
Pn[i] := 0;
Rus: конечный код в ассемблере
Eng: the final code in the assembler
mov %rsp,%rax
movl $0x0,(%rax)
movl $0x0,0x4(%rax)
movl $0x0,0x8(%rax)
movl $0x0,0xc(%rax)
movl $0x0,0x10(%rax)
Rus: Есть ли способы более быстрого очищения массива? Есть ли способы, которые автоматизированы в паскале и не надо самому писать дополнительный код, для ускорения работы программы? С какими подводными камнями мы можем встретиться кроме того, что при неосторожности вылезем за пределы массива и очистим какую-то рабочую область?
Eng: Are there any ways to clear the array faster? Are there any ways that are automated in pascal and you don't need to write additional code yourself to speed up the program? What pitfalls can we encounter besides the fact that, if we are careless, we will get out of the array and clear some working area?