Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
1 2 3 4 |
Test = record A, B, C, D: ^Int32; readonly; //keine Arrays Bla: Array of Byte; readonly; end; |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Schorsch« (12.05.2017, 13:23)
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
ChunkBuffer = record public property Amount: ^Count; readonly; property Current: ^Position; readonly; property Space: ^ChunkSize; readonly; property Data: array of Byte; readonly; constructor(const fixSize: ^ChunkSize; const pos: ^Position; const countBytes: ^Count); begin Data := new array of Byte(fixSize^); Space := fixSize; var offset := new SafeChunkOffset(direction, fixSize, pos); //nicht relevant für Frage^^ var ¤t := new SafeChunkPosition(@offset, countBytes); //nicht relevant für Frage^^ Amount := new SafeChunkCount(fixSize, @¤t, countBytes).Value;//nicht relevant für Frage^^ Current := @¤t.Value; end; |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
ByteChunk = public record private fIsFull: Boolean; fCache: ChunkBuffer; {ON STACK} {the record works internally just with this adress!} fCacheAdr: ^ChunkBuffer; public property RW_Size: BinaryStep read BinaryStep(fCacheAdr^.Amount^); property Space: ChunkSize read fCacheAdr^.Space^; property Current: Position read fCacheAdr^.Current^; constructor(const aSpace: ChunkSize; const start: Position; const binAmount: BinaryStep); begin fIsFull := false; fCache := new ChunkBuffer(@aSpace, @start, @Int64(binAmount)); fCacheAdr := @fCache; end; |
Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von »ProgFrog« (12.05.2017, 14:50)
Ja, C++ alloziert alles auf dem Stack, aber bis auf das class in Pascal auf dem heap alloziert wird, ähnelt sich das Object-Model doch recht gut.
Quellcode |
|
1 |
property Amount: Count read fCache^.Amount^ //heisst: Die "Amount" ist abhängig von dem, auf welchen "Amount" der aktuelle fCache zeigt |
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »ProgFrog« (12.05.2017, 16:02)
Ich meinte aber C++ und da wird per Default alles erstmal auf dem Stack alloziiert
Wenn man eine Struktur oder Klasse auf dem Heap erstellen will, dann reserviert man es über "new" und speichert ja den zurückgegebenen Pointer in einem Struktur/Klassen - Pointer ab.
Werbeanzeige