Autor Beitrag
sk0r
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: So 10.08.08 13:10 
Also, was bringt denn nun ein packed record eigentlich?

Wenn ich in einem Record zwei Integer-Member deklariert habe und sie größe mit sizeof
ausgebe, dann ist mit und ohne das packed Schlüsselwort der Record 8 Bytes groß.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 10.08.08 13:21 
Dann mach mal sus einem Integer ein Word

_________________
Markus Kinzler.
sk0r Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: So 10.08.08 13:33 
Ja, das hat nichts gebracht.
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: So 10.08.08 13:40 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  Test1 = record
    A: Word;
    B: String;
    C: Char;
  end;

  Test2 = packed record
    A: Word;
    B: String;
    C: Char;
  end;


Nimm das und freue dich über 5 Byte Ersparnis :)

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

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 10.08.08 13:47 
Zur eigentlichen Frage: Was wird denn genau anders gemacht? Bringt es immer/nur Vorteile? Warum ist packed nicht der Standard-Record?

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: So 10.08.08 14:07 
Bei einem "normalen" record werden die einzelnen Member so im Speicher ausgerichtet, dass sie immer an einer Speicherstelle stehen, die durch 4 teilbar ist. Dadurch wird der Zugriff darauf optimiert, allerdings entstehen dadurch eventuell Lücken bis zu 3 Bytes jeweils. Beim packed record werden alle Member so dicht wie möglich aneinander geschoben, allerdings ist dann der Zugriff auf manche Member geringfügig langsamer. So habs ich verstanden. :)
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 10.08.08 14:09 
Wobei man das Alignment einstellen kann

_________________
Markus Kinzler.
sk0r Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: So 10.08.08 14:24 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
type Test1 = packed record
    A: Word;
    C: Char;
  end;


ergibt packed 3 und unpacked 4.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 10.08.08 15:57 
Also ist packed auf speicherplatz optimiert und normal auf Laufzeit, danke :think:

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 10.08.08 17:05 
Kann man so nicht sagen. Packed stellt auch sicher, dass der Record noch gelesen werden kann, wenn ein anderes Alignment verwendet wird.