-
-
Save JensMertelmeyer/2691a4b373ce7091ec011daac394b961 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program Project1; | |
function getArrayRefCount(const firstElement): Integer; | |
const | |
SIZE_OF_ELEMENTCOUNT = SizeOf(NativeInt); | |
SIZE_OF_REFCOUNT = SizeOf(Integer); | |
OFFSET = 0 - (SIZE_OF_ELEMENTCOUNT + SIZE_OF_REFCOUNT); | |
var | |
ptr: TPtrWrapper; | |
begin | |
ptr := TPtrWrapper.Create(@firstElement); | |
Result := TMarshal.ReadInt32(ptr, OFFSET); | |
end; | |
var | |
words: TArray<Word>; | |
bytes: TArray<Byte> absolute words; | |
otherWords: TArray<Word>; | |
otherBytes: TArray<Byte>; | |
begin | |
ReportMemoryLeaksOnShutdown := True; | |
words := [$0FF0, $FEFE, $0100]; | |
WriteLn( 'Array ref count: ', getArrayRefCount(words[0]) ); | |
WriteLn( 'Array ref count: ', getArrayRefCount(bytes[0]) ); | |
otherWords := words; | |
Write(sLineBreak); | |
WriteLn( 'Array ref count: ', getArrayRefCount(words[0]) ); | |
WriteLn( 'Array ref count: ', getArrayRefCount(bytes[0]) ); | |
otherBytes := bytes; | |
Write(sLineBreak); | |
WriteLn( 'Array ref count: ', getArrayRefCount(words[0]) ); | |
WriteLn( 'Array ref count: ', getArrayRefCount(bytes[0]) ); | |
readln; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment