5,388
社区成员
发帖
与我相关
我的任务
分享
function _NewAnsiString(length: Longint): Pointer;
asm
TEST EAX,EAX
JLE @@null
PUSH EAX
ADD EAX,rOff+2 // one or two nulls (Ansi/Wide)
AND EAX, not 1 // round up to even length
PUSH EAX
CALL _GetMem
POP EDX // actual allocated length (>= 2)
MOV word ptr [EAX+EDX-2],0 // double null terminator
ADD EAX,rOff
POP EDX // requested string length
MOV [EAX-skew].StrRec.length,EDX
MOV [EAX-skew].StrRec.refCnt,1
RET
@@null:
XOR EAX,EAX
end;
procedure foo(x: array of Byte);
begin
end.
procedure bar;
var a: array of Byte;
begin
SetLength(a, 1024*1024);
foo(a);
end;
function ByteArrayToStr(src:pointer; srclen:dword):AnsiString;
asm
push ecx
push eax
push edx
push edx
mov eax,ecx
call system.@lstrClr
pop edx
mov eax,edx
add eax,10
and eax,not 1
push eax
call system.@getmem
mov dword ptr[eax],1
pop edx
mov word ptr[eax+edx-2],0
pop ecx
mov [eax+4],ecx
lea edx,[eax+8]
pop eax
push edx
call move
pop eax
pop ecx
mov [ecx],eax
end;