Autor Beitrag
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Do 05.08.10 21:07 
Hallo Delphianer,

Lasst mich doch mal euch etwas vorrechnen...:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
TTileDataRec = Record
    x: Byte;
    y: Byte;
    Tileset: Byte;
  End;

  TTileRec = Record
    Layer: array[1..5of TTileDataRec;
    Typ: Byte;
    Data1: LongInt;
    Data2: LongInt;
    Data3: LongInt;
    BlockDir: Byte;
  End;

5*3 bytes = 15 + 1 + 4 + 4 + 4 + 1 = 29...
Computer sagt nein...
Für ihn sind das 32 bytes.
Wo liegt mein Fehler ich find den nicht :nixweiss:

Ich hab mich grad mal an nen altes Thema zurückerinnert.
Mit nem packed Record gehts.
Kanns mir einer erklären?


Moderiert von user profile iconNarses: Topic aus Dateizugriff verschoben am Do 05.08.2010 um 22:58
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 05.08.10 21:37 
Bei einem normalen Record werden zur Optimierung die Felder an 4-Byte jeweils ausgerichtet (Stichwort: 4-Byte-Alignment). Dadurch ist dazwischen immer etwas Platz, wenn du z.B. nur 1 Byte hast, aber der Zugriff ist schneller.

Bei einem packed Record wird jedes Byte ausgenutzt, so dass du die reale Größe hast. Genau dafür ist packed da.
Niko S. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Do 05.08.10 22:24 
Okay das erklärt natürlich warum er 32 lieber mag als 29.
Dankeschön für die Erklärung.