Autor Beitrag
Pbg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98
D3 Prof.
BeitragVerfasst: Di 01.07.03 21:57 
ich möchte einen Datensatz einlesen der 256 byte lang ist und dessen Inhalt ich kenne. Der Satz kommt aus einem Dos Programm. Nun möchte ich rausfinden wie das Programm die Daten speichert, damit ich Sie in anderen Programmen verwendenkann.

Bisher habe ich es so declariert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
 type Stammdaten = record
      Name1 : ARRAY[0..12OF CHAR;
      Name2 : ARRAY[0..4OF CHAR;
      Name3 : ARRAY[0..3OF CHAR;
      Name4 : ARRAY[0..19OF CHAR;
      Name5 : ARRAY[0..29OF CHAR;
      Name6 : ARRAY[0..12OF CHAR;
      unbestimmt2 : ARRAY[0..2OF CHAR;
      name7 : longint ;
      name8 : longint;
      name9 : longint;
      name10 : longint;
      name11 : longint;

      unbestimmt7 : smallint;  //??
     
                //name12 : longint;
                unbestimmt5 :  ARRAY[0..65OF CHAR;  

      unbestimmt7 : ARRAY[0..0OF CHAR;
      unbestimmt6 :  ARRAY[0..39OF CHAR;
      name12 : ARRAY[0..9OF CHAR;
      unbestimmt3: ARRAY[0..0OF CHAR;
      name13 : ARRAY[0..12OF CHAR;
      unbestimmt4 : ARRAY[0..14OF CHAR;
      end;


bis hierher funzt es. Wenn ich nun name12 mit einsetzte und dafür von unbestimmt5 4 abziehe array[0-61] verschiebt er mir alle Sätze. für Longint nimmt er an dieser Stelle 8 Byte und nicht 4 byte. WEiß jemand woran das liegen kann ???

Vielen Dank
MfG

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
Brueggendiek
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 304

Win 98, Win98SE, Win XP Home
D5 Std
BeitragVerfasst: Di 01.07.03 23:04 
Hallo!

Das Problem liegt an der automatischen Ausrichtung der Variablen im Speicher. Deklariere das Ganze mal so:
ausblenden Delphi-Quelltext
1:
type Stammdaten = packed record					

Rest wie vorhanden. Dann sollte das klappen.

Gruß

Dietmar Brüggendiek
Pbg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98
D3 Prof.
BeitragVerfasst: Di 01.07.03 23:26 
Hallo,

Danke für die schnelle Antwort.

Klappt jetzt super :o)

MfG
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mi 02.07.03 21:16 
was macht denn packed ?

_________________
MFG
Michael Springwald, "kann kein englisch...."
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 02.07.03 21:26 
8) Bei packed ist das Field-alignment ausgeschaltet...

Will heissen die daten werden nicht an einem 32bit raster ausgerichtet, liege direkt hintereinander, ohne lücken, im speicher.

_________________
mfg.
mâximôv
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mi 02.07.03 22:12 
könntes du mal ein beispiel posten wo man den unterschied merkt ?
kann es mir nicht so richtig vorstellen :(

_________________
MFG
Michael Springwald, "kann kein englisch...."
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 02.07.03 23:34 
benutz dein vorstellungsvermögen und stell dir vor, dies wären bytes im speicher ( 32bit schritte durch '|' markiert) :


~~~~|~~~~|~~~~|~~~~| => leerer speicher

ww~~|ww~~|~~~~|ww~~| => 4 words mit alignment(Ausrichtung)

wwww|~~ww| => 4 words ohne alignment (also mit packed)

ddddd|ddddd|~~~~|dddd| => 4 DWords mit alignment

ddddd|ddddd|~~~~|dddd| => 4 DWords ohne alignment

...hier kannst du ganz klar erkennen, dass das alignment auf 32bit-typen optimiert ist (zumindest auf unserem system) und die anderen typen haben wenigstens schnellen zugriff, verschwenden aber viel speicher.

Wenn du mit typisierten record-dateien arbeitest, dann solltest du unbedingt packed records verwenden :wink: weil sonst die ganzen speicherlöcher mit gespeichert werden.

hoffe das war verständlich?

_________________
mfg.
mâximôv
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 03.07.03 08:44 
Allerding ist bei strukturierten Typen, die in einem Word- oder Doubleword Raster ausgerichtet sind, der Zugriff schneller.

Gurß
Tino
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Do 03.07.03 13:05 
danke, für die antwort, also wenn man packed verwendet geht es zwar langsammer aber es wird nicht so viel speicherverschwendet, richtig?

_________________
MFG
Michael Springwald, "kann kein englisch...."
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Do 03.07.03 14:14 
Richtig.

Gruß
Klabautermann
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Do 03.07.03 17:04 
Noch ein Zusatz:
Wenn man einen record, der nicht packes ist, und der "ungerade" Datentypen hat, in einen Stream speichern will, liegen die Daten nicht so vor, wie man es erwarten könnte, sondern auch unaligned. Es sind also Leerbytes drin, die gar nicht hingehören (das hat mir mal einen Tag geraubt, bis ich rausgekriegt habe, warum mein Stream nicht meinen Vorstellungen entspricht...)

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Fr 04.07.03 00:21 
tommie-lie hat folgendes geschrieben:
... liegen die Daten nicht so vor, wie man es erwarten könnte, sondern auch unaligned. Es sind also Leerbytes drin, ...


du meinst aligned...oder irre ich mich :?:

ich denke: Alignment = ausrichtung am raster

_________________
mfg.
mâximôv
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Fr 04.07.03 15:12 
... ach, macht doch was ihr wollt!
Natürlich hast du Recht, aber zu der späten Abendstund kann ich doch die beiden Buchstaben "un" nicht mehr erkennen... :mrgreen:

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert