我正在寻找GIS/Geometric算法:
我有1000个点随机分布在一个大区域(如城市),我怎样才能找到所有超过15分的小区域?如下图所示:

每个点都有自己的纬度和经度坐标.小面积小于200米x 200米.
我声明了两个全局变量:
var
gIsRunning: Boolean = False;
gLogCounter: Integer = 0;
Run Code Online (Sandbox Code Playgroud)
这些变量仅在主线程中写入,并在其他线程中读取.在这种情况下,这些变量是否安全?
我使用AllocMem/GetMem/New例程来分配内存,然后使用FreeMem/Dispose例程来释放内存.但我发现(通过Process Explorer)进程的内存大小没有减少.
如果我使用GlobalAllocPtr/HeapAlloc和GlobalFreePtr/HeapFree API,内存大小将减少.
这是我的测试代码:
type
TMyRec = record
Name: string;
TickCount: Cardinal;
Buf: array[0..1024 - 1] of byte;
end;
PMyRec = ^TMyRec;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormDestroy(Sender: TObject);
begin
FList.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FList := TList.Create;
ReportMemoryLeaksOnShutdown := true;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
Size: Integer;
Rec: PMyRec;
Heap: Cardinal;
begin
Size := SizeOf(TMyRec);
Heap := GetProcessHeap;
for I := 0 to 2000 - 1 do
begin
Rec := AllocMem(Size); // Delphi …Run Code Online (Sandbox Code Playgroud) It makes me confused when I read the article by Zarko Gajic today:
"Multithreaded Delphi Database Queries"
Article URL: http://delphi.about.com/od/kbthread/a/query_threading.htm
Sourecode: http://delphi.about.com/library/weekly/code/adothreading.zip
With the code of "TCalcThread.Execute" procedure, Why the following code do not need to be placed in the Synchronize() method to run?
Line 173: ListBox.Clear;
Line 179: ListBox.Items.Insert(......);
Line 188: ListBox.Items.Add('*---------*');
Line 195: TicksLabel.Caption := 'Ticks: ' + IntToStr(ticks);
Run Code Online (Sandbox Code Playgroud)
These codes are operating the VCL components, and are related to the UI updates. In my knowledge, …
我有一个提供解码功能的DLL,如下所示:
function MyDecode (Source: PChar; SourceLen: Integer; var Dest: PChar; DestLen: Integer): Boolean; stdcall;
Run Code Online (Sandbox Code Playgroud)
HostApp调用"MyDecode",并转移到Source,SourceLen和Dest参数,DLL返回解码的Dest和DestLen.问题是:HostApp无法知道解码的Dest长度,因此不知道如何预先分配Dest的内存.
我知道可以将"MyDecode"分成两个函数:
function GetDecodeLen (Source: PChar; SourceLen: Integer): Integer; stdcall; // Return the Dest's length
function MyDecodeLen (Source: PChar; SourceLen: Integer; var Dest: PChar): Boolean; stdcall;
Run Code Online (Sandbox Code Playgroud)
但是,我的解码过程非常复杂,因此如果分成两个功能会影响效率.
有更好的解决方案吗?
是亚历山大,这可能是一个很好的解决方案.HostApp代码:
//...
MyDecode(....)
try
// Use or copy Dest data
finally
FreeDecodeResult(...)
end;
Run Code Online (Sandbox Code Playgroud)
DLL代码:
function MyDecode(...): Boolean;
begin
// time-consuming calculate
// Allocate memory
GetMem(Dest, Size);
// or New()?
// or HeapAlloc()?
end;
procedure FreeDecodeResult(Dest: PChar);
begin
FreeMem(Dest); …Run Code Online (Sandbox Code Playgroud) 看下面的代码,为什么Trunc函数的结果不同?
procedure TForm1.Button1Click(Sender: TObject);
var
D: Double;
E: Extended;
I: Int64;
begin
D := Frac(101 / 100) * 100;
E := Frac(101 / 100) * 100;
I := Trunc(D);
ShowMessage('Trunc(Double): ' + IntToStr(I)); // Trunc(Double): 1
I := Trunc(E);
ShowMessage('Trunc(Extended): ' + IntToStr(I)); // Trunc(Extended): 0
end;
Run Code Online (Sandbox Code Playgroud) 准备开发内部通信协议,尝试使用XML或者JSON作为序列化机制,但是文本方式效率较低,导致数据包量大。所以,我希望使用二进制序列化编码机制。但是,我找了半天,没找到跨语言、Delphi支持的机制。
我需要将大量行插入到我的 PostgreSQL(v9.5) 表中。
这是表格:
create table TaskLog(
id serial,
taskid integer,
x double precision,
y double precision,
loc character varying(50),
speed smallint,
gpstime timestamp without time zone,
veh character varying(16),
vin character(17),
regdate date,
enabled boolean,
remake character varying(100),
isdel boolean,
alarm integer,
CONSTRAINT pk_delphi_id PRIMARY KEY (id)
)
Run Code Online (Sandbox Code Playgroud)
我使用 FireDAC(Delphi XE10.1) 插入行:
function RandomStr(aLength : Integer) : string;
var
X: Integer;
begin
if aLength <= 0 then exit;
SetLength(Result, aLength);
for X:=1 to aLength do
Result[X] := Chr(Random(26) + …Run Code Online (Sandbox Code Playgroud) delphi ×10
memory ×2
binary ×1
c ×1
c++ ×1
delphi-2009 ×1
dll ×1
firedac ×1
gis ×1
postgresql ×1
protocols ×1
synchronize ×1
xml ×1