[fpc-pascal] Array [THandle] of pointer

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Dec 24 00:16:53 CET 2008


On 24 Dec 2008, at 00:02, Andrew Brunner wrote:

> Following Setup:
>  Ubuntu 8.10 x64
>  FPC 2.2.3 (latest and greatest)
>  Lazarus (Latest and greatest)
>
> I'm seeing an anomaly with reading/writing to an Array[THandle] of  
> Pointers.
>
> TMyStruct=record
>  Index:integer;
> end;
> PMyStruct=^TMyStruct;
> TMyList = Array[THandle] of PMyStruct;
>
>
> If I declare a localized variable
> procedure Test();
> var
>  MyTest:TMyList;
>  hThread:THandle;
> begin
>  hThread:=getCurrentThreadID;
>  if (MyTest[hThread])=nil then begin // <---- CRASH HERE EXTERNAL  
> SIGBUS
>  end;
> end;

thandle is a longint on fpc/linux, so you're declaring an array of  
2^32 * 8 bytes (32GB) on the stack here. That may be valid on linux/ 
x86_64, but it also may not be (I don't know what Linux' stack limits  
are). It's definitely not something that would seem advisable to me.

I'm surprised this is supposed work with Delphi since thandle is a  
dword for Windows, so you're still ending up with an array of 2^32 * 4  
bytes (16 GB) on Win32. There's simply no way to map that much memory  
at once in 32 bit process' address space.


Jonas



More information about the fpc-pascal mailing list