BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Fastcode MM B&V 0.35

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM
View previous topic :: View next topic  
Author Message
Dennis
Guest





PostPosted: Thu May 05, 2005 9:20 am    Post subject: Re: Fastcode MM B&V 0.35 Reply with quote



Hi

Could somebody review this new validation function?

//Grow dynamic array with STEPSIZE from MIN to MAX and validate that it is 4
byte aligned

function TMMValidation.Validate22 : Boolean;
var
SomeArray : array of Byte;
MemoryStatus : TMemoryStatus;
BytesToAllocate, StartAddress, I2, I3, OldBytesToAllocate : Cardinal;
const
BYTESTOALLOCATESTEPSIZE : Cardinal = 2;
BYTESTOALLOCATEMIN : Cardinal = 5;//5 byte
BYTESTOALLOCATEMAX : Cardinal = 50*1024*1024;//50 Mbyte
FILLBYTE : Byte = 255;

begin
try
Result := True;
OldBytesToAllocate := 1;
//Allocate
SetLength(SomeArray, 1);
SomeArray[0] := FILLBYTE;
BytesToAllocate := BYTESTOALLOCATEMIN;
while BytesToAllocate <= BYTESTOALLOCATEMAX do
begin
GlobalMemoryStatus(MemoryStatus);
if MemoryStatus.dwAvailVirtual >= BytesToAllocate then
begin
//Reallocate
SetLength(SomeArray, BytesToAllocate);
//Old data preserved?
for I3 := 0 to OldBytesToAllocate-1 do
begin
if SomeArray[I3] <> FILLBYTE then
begin
Result := False;
Exit;
end;
end;
//4 byte alignment?
//Add 8 byte offset to compensate for refcount and size data
StartAddress := Cardinal(@SomeArray[8]);
if StartAddress mod 4 <> 0 then
begin
Result := False;
Exit;
end;
//Fill newly allocated space
for I2 := OldBytesToAllocate to BytesToAllocate-1 do
SomeArray[I2] := FILLBYTE;
OldBytesToAllocate := BytesToAllocate;
BytesToAllocate := BytesToAllocate * BYTESTOALLOCATESTEPSIZE;
end;
end;
//Free
SetLength(SomeArray, 0);
except
Result := False;
end;
end;

Regards
Dennis


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.