Autor Beitrag
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Do 17.02.05 00:06 
Ich habe mehrere String Konstanten global deklariert.

ausblenden Delphi-Quelltext
1:
2:
const
 KONSTANTER_STRING = 'Ich bin ein String';


Darf ich in Threads auf diese Strings lesend zugreifen?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure Thread.Execute;
begin
 TuEtwas(KONSTANTER_STRING);
end;


In Delphi 3 war das String-Handling noch anders und ergab öfters Probleme mit Threads.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 17.02.05 00:09 
Theoretisch sollte es keine Probleme geben, praktisch solltest Du's testen und im Notfall CriticalSections zum Threadblocking nutzen. IMHO.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Spaceguide Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Do 17.02.05 00:13 
Also bevor ich Critical Sections einsetze (sehr umständlich und nicht performant) nehme ich lieber PChars oder definiere die Konstanten z.B. als klassischen String mit String[80] etc. Mit Thread und "Testen" fällt man meist schön auf die Schnauze, weil ein Bug z.B. nur alle 50000 mal auftritt oder noch schlimmer.
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Do 17.02.05 00:32 
Spaceguide hat folgendes geschrieben:
Darf ich in Threads auf diese Strings lesend zugreifen?

Ich sehe da keine Probleme.

Zitat:
In Delphi 3 war das String-Handling noch anders und ergab öfters Probleme mit Threads.

Ein String der mit const deklariert ist, ist ja nicht vom Typ AnsiString.

_________________
Ciao, Sprint.
UC-Chewie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 531

WinXP
D5 Ent
BeitragVerfasst: Do 17.02.05 12:36 
Das sollte keine Probleme geben. Schließlich liegt der String konstant vor und wird nicht verändert.
Bei Ansi-Strings könnte es höchstens aufgrund der Referenzzählung zu Synchronisationsproblemen kommen.

_________________
Egal wie dumm man selbst ist, es gibt immer andere, die noch dümmer sind
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 17.02.05 13:13 
UC-Chewie hat folgendes geschrieben:
Bei Ansi-Strings könnte es höchstens aufgrund der Referenzzählung zu Synchronisationsproblemen kommen.

Seit Delphi5 ist aber auch die Referenzzählung threadsafe..

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Spaceguide Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Do 17.02.05 13:13 
Ja, ich habe gesehen, dass Delphi den String dann einfach in den passenden Stellen einsetzt, er kommt dann auch mehrmals in der EXE vor.