Autor Beitrag
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Sa 23.09.06 13:04 
Hi,

ich habe einen Record:
ausblenden Delphi-Quelltext
1:
2:
3:
TColor = Record
  R, G, B, A: Single;
end;


Der ist jetzt 4 * 4 Byte groß = 16 Byte.
Um speicher zu sparen würde ich nun gerne optional die RGBA Werte auch als Byte speichern..

Im moment löse ich es indem ich einfach zwei verschiedene Records habe und je nachdem welchen ich brauche den richtigen verwende.. aber das ist extrem umständlich irgendwie..

Deshalb, gibt es irgendwie eine möglichkeit etwas derartiges zu schaffen?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
TColor = Record
  Format: TColorFormat;
  if Format = cfFloat then
    R, G, B, A: Single
  else
    R, G, B, A: Byte;
end;


Also so, das der Record im Arbeitsspeicher dann auch wirklich nur je nach auswahl 16, bzw. 4 Byte groß ist?

Aya~

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
cuejo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP
Delphi 7 Personal und 2005 PE
BeitragVerfasst: Sa 23.09.06 13:10 
Ja, gibt es. Guck dir hier mal Variante Records an.

_________________
Computer sind dumm, aber fleißig. Deshalb arbeite ich so gerne damit.
Aya Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Sa 23.09.06 13:17 
Hi,

Geht leider nicht.. denn:
Zitat:
Die Teile hinter case teilen sich denselben Speicherbereich. Der Compiler reserviert so viel Platz wie die größte Variante benötigt. Deshalb können auch variante Records in typisierten Dateien verwendet werden.


Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
cuejo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP
Delphi 7 Personal und 2005 PE
BeitragVerfasst: Sa 23.09.06 14:22 
Du könntest Pointer verwenden, denn die sind immer gleich groß. Etwa so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
type
  TSingleRecord = record
    R,B,G,A: single;
  end;

  TByteRecord = record
    R,G,B,A: byte;
  end;

  TVariantRecord = record
    case Format: TColorFormat of
      cfFloat: (FloatColor: ^TSingleRecord);
      cfInt: (IntColor: ^TByteRecord);
  end;

Aber das macht das ganze nicht übersichtlicher und auch nicht einfacher zu bedienen. :?

_________________
Computer sind dumm, aber fleißig. Deshalb arbeite ich so gerne damit.