delphi 中申明应该是 procedure GetMem(var P:Pointer;Size:Integer);
我模仿着写了一个 procedure GetMemEx(var P:Pointer;Size:Integer);
原本以为一模一样。
但是,我随便写了一个指针类型
type
PMyRecord = ^TMyRecord;
TMyRecord = record
X:Integer;
Y:Double;
Z:string[10];
end;var pp:PMyRecord;
begin
GetMem(pp,32);
GetMemEx(pp,32);结果我写的函数报错: [Pascal Error] Unit1.pas(91): E2033 Types of actual and formal var parameters must be identical如果改成 GetMemEx(Pointer(pp),32); 强制转换一下就 ok为什么会这样?
我模仿着写了一个 procedure GetMemEx(var P:Pointer;Size:Integer);
原本以为一模一样。
但是,我随便写了一个指针类型
type
PMyRecord = ^TMyRecord;
TMyRecord = record
X:Integer;
Y:Double;
Z:string[10];
end;var pp:PMyRecord;
begin
GetMem(pp,32);
GetMemEx(pp,32);结果我写的函数报错: [Pascal Error] Unit1.pas(91): E2033 Types of actual and formal var parameters must be identical如果改成 GetMemEx(Pointer(pp),32); 强制转换一下就 ok为什么会这样?
procedure GetMem(var P:Pointer;Size:Integer);
你是在哪看到的
UnitSystemCategorydynamic allocation routinesDelphi syntax:procedure GetMem(var P: Pointer; Size: Integer);DescriptionP is a variable of any pointer type. Size is an expression specifying the size in bytes of the dynamic variable to allocate. Access the newly allocated memory by dereferencing the pointer; that is, use P^. P is a variable of any pointer type
已经说明P是任意指针类型变量,估计做过处理了,详细就不清楚了
2 你那个函数是怎样实现的呢?
0045ADF5 E8C278FAFF call @GetMem
0045ADFA C3 ret
0045ADFB 90 nop 这段代码只有传入参数 $000000c8 200, 应该是编译器优化了的
我也认为 Delphi 是通过 MemManage 调用了 _GetMem 函数。
好吧,太复杂的问题,我就不细究了。