我正在将代码从D2007迁移到XE8.我有一个使用此数据结构的函数:
Map: array[Char] of Byte = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,
..............
0, 0, 0, 0, 0, …Run Code Online (Sandbox Code Playgroud) 我有以下数据结构,我想快速(明显)和稳定地对其进行排序。您认为哪种算法合适?
type
PSuperListItem = ^TSuperListItem;
TSuperListItem = record
SubItems : array of String;
Marked : Boolean;
ImageList : Byte;
ImageIndex: Integer;
Data : Pointer;
end;
TSuperListItems = array of PSuperListItem;
var
Items: TSuperListItems;
Run Code Online (Sandbox Code Playgroud)
我在这里发现只有插入、冒泡和合并排序算法是稳定的。我知道合并排序用于对链表进行排序。对于其他两种算法我一无所知,但我有一种奇怪的感觉,它们速度较慢。所以我不知道该使用哪种算法。
我想为具有相同ID的观测值计算Stata中的增长率。我的数据以简化的方式看起来像这样:
ID year a b c d e f
10 2010 2 4 9 8 4 2
10 2011 3 5 4 6 5 4
220 2010 1 6 11 14 2 5
220 2011 6 2 12 10 5 4
334 2010 4 5 4 6 1 4
334 2011 5 5 4 4 3 2
Run Code Online (Sandbox Code Playgroud)
现在,我想根据2010年到2011年的变量af为每个ID增长率计算:
例如对于ID 10和变量a,它将是:(3-2)/ 2,对于变量b:(5-4)/ 4等,并将结果存储在新变量中(例如,growth_a,growth_b等)。
由于我有超过12万个观测值和约300个变量,是否有一种有效的方法(循环)?
我的代码如下所示(简化):
local variables "a b c d …Run Code Online (Sandbox Code Playgroud) 我正在使用Assembly在Delphi中编写一些函数.所以我想把它放在一个名为的.pas文件中Strings.pas.用于uses新的Delphi软件.我需要写什么才能使它成为一个有效的库?
我的功能是这样的:
function Strlen(texto : string) : integer;
begin
asm
mov esi, texto
xor ecx,ecx
cld
@here:
inc ecx
lodsb
cmp al,0
jne @here
dec ecx
mov Result,ecx
end;
end;
Run Code Online (Sandbox Code Playgroud)
这会计算字符串中字符的数量.如何在lib中创建它Strings.pas以uses Strings;在我的表单中调用?
MOVMSKB将字节字段打包成位是一件非常好的工作.
但是我想反过来.
我有一个16位的字段,我想放入XMM寄存器.
每位1字节字段.
优选地,设置位应该设置每个字节字段的MSB(0x80),但是我可以使用设置位,从而在字节字段中产生0xFF结果.
我在https://software.intel.com/en-us/forums/intel-isa-extensions/topic/298374上看到了以下选项:
movd mm0, eax
punpcklbw mm0, mm0
pshufw mm0, mm0, 0x00
pand mm0, [mask8040201008040201h]
pcmpeb mm0, [mask8040201008040201h]
Run Code Online (Sandbox Code Playgroud)
但是,此代码仅适用于MMX寄存器,不能与XMM regs一起使用,因为pshufw不允许这样做.
我知道我可以使用PSHUFB,但是那是SSSE3而我想拥有SSE2代码,因为它需要在任何AMD64系统上运行.
有没有办法做到这一点是纯SSE2代码?
请不要内在,只需简单的intel x64代码.
我正在编写一个包含很少组件的组件.
TMyComponent = class(TPanel)
private
fGrid : TExCustomDBGrid;
fOnCellClick : TDBGridClickEvent;
public
constructor Create(AOwner: TComponent); override;
published
property OnCellClick: TDBGridClickEvent read FOnCellClick write FOnCellClick;
End;
...
constructor TMyComponent .Create(AOwner: TComponent);
begin
inherited;
fGrid := TExCustomDBGrid.Create(self);
fGrid.parent := self;
fGrid.Align := alClient;
end;
Run Code Online (Sandbox Code Playgroud)
我希望能够将事件从组件(TPanel)传播到包含的fGrid.我怎样才能实现这一目标?
我想我应该在TPanel上声明一个具有相同类型的事件(作为容器组件).那么如何传播到fGrid?
我想知道是否有办法在运行时获取对象的类名。我的意思是这样的:这是我非常简单的脚本
person=TPerson:new()
Run Code Online (Sandbox Code Playgroud)
我想在我的应用程序(在delphi中)中获取“TPerson”,我用lua调试信息尝试了它,但我知道要获取的是函数“new”,但我需要获取类“TPerson”
lua_getstack(l,0,PL_Debug);
lua_getfield(l,LUA_GLOBALSINDEX,'f');
lua_getinfo(l,'n',PL_Debug);
nameOfCurrnetFunction:=PL_Debug.name; // here is stored "new"
Run Code Online (Sandbox Code Playgroud)
那么可以获得类名吗?谢谢
我正在使用以下例程来修补RTL中的函数.
procedure PatchCode(const AddrProc: Pointer; const CodeSize: NativeUInt;
const Code: Pointer);
var
OldProtect: Cardinal;
begin
VirtualProtect(AddrProc, CodeSize, PAGE_EXECUTE_READWRITE, OldProtect);
Move(Code^, AddrProc^, CodeSize);
VirtualProtect(AddrProc, CodeSize, OldProtect, OldProtect);
end;
Run Code Online (Sandbox Code Playgroud)
但是当我调整我的补丁方法时,它们的大小会发生变化,导致这样的代码破坏:
//PatchRedirect calls PatchCode internally
PatchRedirect(AddrGetMem,{codesize = }17, @RedirectGetMem, JUMPS_GETMEM);
Run Code Online (Sandbox Code Playgroud)
有没有办法在编译时或运行时确定方法的大小?(任何一个都很好).
我希望有一个通用的解决方案,但如果它只适用于asm例程,那对我的目的来说很好.
使用案例
一个用例就是FillChar的更快版本.
99%的时间FillChar用作a ZeroMem.所以我补丁System.ZeroMem:
xor r8,r8
jmp FastFillChar;
Run Code Online (Sandbox Code Playgroud)
我修补System.FillChar与
movzx R8,R8b
mov r9,$0101010101010101
imul r8,r9
jmp FastFillChar
Run Code Online (Sandbox Code Playgroud)
这样我可以使99%的情况下FillChar更快一点.
或者,如果有人打扰实际使用zeromem
更新
感谢Rudy我认为我有一个适用于有限子集的解决方案.
我创建了一个动态数组,并将值传递给它.是否有找到动态数组平均值的快捷方式.
var
TheMin, TheMax: Integer;
x: array of Integer; //Dynamic array declaration
....
TheMin := MinIntValue(x);//I am able to retrieve the minium value of the dynamic array
TheMax := MaxIntValue(x);//I am able to retrieve the maximum value of the dynamic array
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以使用数学库.