Autor Beitrag
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mo 18.06.07 14:41 
Hallo,

ich habe mich heute gefragt ob es sinnvoll wäre für kleinere Schleifen statt Integer z.b. Byte zu nehmen.

Das geht natürlich nur für Schleifen, deren Anzahl an Durchläufen ich bereits zur Entwicklungszeit kenne.

Würde das den Speicher schonen, oder meint ihr es ist unnötig?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure Bla;
var
  i: Integer;
  j: Byte;
begin
  for i := 0 to 10 do
    // irgendwas
  for j := 0 to 10 do
    // irgendwas
end;

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 18.06.07 14:42 
Was machen 3 Bytes aus?

_________________
Markus Kinzler.
Chatfix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mo 18.06.07 14:46 
Das wollte ich ja eben wissen.
Man hat zum Beispiel weniger Tipp-Arbeit, da Byte kürzer ist als Integer, und bei großen Projekten wo generell viel Speicher gebraucht wird.

War halt nur eine Frage die mich beschäftigt hat.

Könnte es nicht auch schneller gehen wenn er weniger Speicher brauch? (Ich weis wir reden hier von Zeitfenstern die wir nicht merken, es geht rein um die theorie)

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mo 18.06.07 14:47 
Im Zuge der Optimierung wird das ganze eh meistens wieder auf 4-Byte-Grenzen ausgerichtet.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Chatfix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mo 18.06.07 14:49 
Es könnte also sogar sein das er für die Optimierung wieder Zeit verliert, bzw Speicher halt "leer" belegt?

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mo 18.06.07 14:51 
Dafür wird er IMHO keine Zeit verlieren, aber der Speicher wird dann halt nicht genutzt.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 18.06.07 16:55 
Wenn dir Integer zu lang ist:

ausblenden Delphi-Quelltext
1:
2:
type
  A = Integer;


;-) [bitte nicht machen xD]

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Chatfix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Di 19.06.07 08:04 
user profile iconGTA-Place hat folgendes geschrieben:
Wenn dir Integer zu lang ist:

ausblenden Delphi-Quelltext
1:
2:
type
  A = Integer;


;-) [bitte nicht machen xD]


Sehr witzig...
Mir ging es hier nur um die Theorie.

Ich fasse aus dem Thread also folgenden Schluss:
Nimm Integer da der Speicher sowieso reserviert wird.

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
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: Di 19.06.07 08:16 
Durch die Verwendung von Byte und Word-Variablen verlierst Du eher Zeit, da die CPU auf 32-Bit-Daten optimiert ist. Wenn sie auf 8-Bit und 16-Bit-Daten zugreifen muss sind zusätzliche Schritte notwendig, die u.U. Zeit kosten.

_________________
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.