Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

А что представляет из себя переменная типа string [D7, WinXP]


Страницы:   1 2

Pavel__ ©   (2005-09-09 21:38:00) 

...после объявления в var? И будет ли отличие при двух нижеследующих примерах:


// 1

var
 S: string;
begin
 S := '';
 ...
end;

// 2
var
 S: string;
begin
 ...
end;


Заранее извиняюсь, если спросил глупость. С уважением.


Eraser   (2005-09-09 23:19:00) [21]

DesWind ©   (09.09.05 23:14) [14]

Пустая строка действительно просто указатель - 4 байта, но
вообще string это не просто указатель! , т.к. When the variable is nonempty, it points a dynamically allocated block of memory that contains the string value. The eight bytes before the location contain a 32-bit length indicator and a 32-bit reference count.


DesWind   (2005-09-09 23:14:00) [22]

В чем я не прав?
A long-string variable is a pointer occupying four bytes of memory.

А вот за это я и получил четверку

The eight bytes before the location contain a 32-bit length indicator and a 32-bit reference count.


Eraser   (2005-09-09 23:11:00) [23]

iXT   (09.09.05 23:04) [12]

Это уж точно! )

DesWind ©   (09.09.05 23:02) [11]

Это можно сказать указатель, типа как PChar, но не совсем.

читай справку и рамблер!

AnsiString, also called a long string, represents a dynamically allocated string whose maximum length is limited only by available memory.

A long-string variable is a pointer occupying four bytes of memory. When the variable is empty--that is, when it contains a zero-length string--the pointer is nil and the string uses no additional storage. When the variable is nonempty, it points a dynamically allocated block of memory that contains the string value. The eight bytes before the location contain a 32-bit length indicator and a 32-bit reference count. This memory is allocated on the heap, but its management is entirely automatic and requires no user code.

Because long-string variables are pointers, two or more of them can reference the same value without consuming additional memory. The compiler exploits this to conserve resources and execute assignments faster. Whenever a long-string variable is destroyed or assigned a new value, the reference count of the old string (the variable's previous value) is decremented and the reference count of the new value (if there is one) is incremented; if the reference count of a string reaches zero, its memory is deallocated. This process is called reference-counting. When indexing is used to change the value of a single character in a string, a copy of the string is made if--but only if--its reference count is greater than one. This is called copy-on-write semantics.


http://doc.trecom.tomsk.su/Delphi/DevelopersCorner/www.akzhan.midi.ru/devcorner/akdeltnt-content/akdeltnt-0033.html


iXT   (2005-09-09 23:04:00) [24]

Eraser ©   (09.09.05 22:55) [10]

Но и не статический массив, согласись!


DesWind   (2005-09-09 23:02:00) [25]

Eraser ©   (09.09.05 22:55) [10]

А что?


Eraser   (2005-09-09 22:55:00) [26]

DesWind ©   (09.09.05 22:01) [6]
Указатель.


Не совсем...


DesWind   (2005-09-09 22:53:00) [27]

Я и привел как цитату.


iXT   (2005-09-09 22:49:00) [28]

DesWind ©   (09.09.05 22:06) [7]

В чем?


DesWind   (2005-09-09 22:06:00) [29]

iXT   (09.09.05 21:57) [5]

а отличия, нет.


DesWind   (2005-09-09 22:01:00) [30]

Из-за этого вопроса я на экзамене схлопотал сетверку.... Указатель.


iXT   (2005-09-09 21:57:00) [31]

Дкльфа умная: после объявления ='' (Length(str)=0). И массив не статический!


Pavel__   (2005-09-09 21:50:00) [32]

2 MBo

грубо говоря я об этом "Если статический массив, то после объявления в нём часто мусор, обнулять приходится, а string тоже массив, может тоже мусор.."

Слышал звон..


begin...end   (2005-09-09 21:49:00) [33]


> vrem   (09.09.05 21:45) [1]

> будет больше отличия если
> var s:string[30] <---- памяти меньше, чем просто string

Почему меньше?


vrem   (2005-09-09 21:45:00) [34]

Если статический массив, то после объявления в нём часто мусор, обнулять приходится, а string тоже массив, может тоже мусор..
будет больше отличия если
var s:string[30] <---- памяти меньше, чем просто string


MBo   (2005-09-09 21:45:00) [35]

Собственно говоря, ты ничего и не спросил...


Страницы:   1 2

Наверх

Титульная страница Поиск, карта сайта Написать письмо