Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-12

Array [THandle] of pointer

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrew Brunner

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;

This should not crash here. It should have been nil.

Any work being done in this area or should I report another bug?

Jonas Maebe
to Andrew Brunner
Andrew Brunner wrote 26 lines
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

Marc Weustink
to Andrew Brunner: Following Setup: Ubuntu 8.10 x64 FPC 2.2.3 (latest and greatest) Lazarus (Latest and…
Andrew Brunner wrote 29 lines
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; This should not crash here. It should have been nil. Any work being done in this area or should I report another bug?

I'm surprised it crashes there. A THandle is IIRC a Cardinal on unix, so by defining a variable MyTest:TMyList, you allocate 4GB * SizeOf(TMyStruct) = 16GB on your stack. Usually a process doens't have that much space and I wonder if you wanted this.

(You may want to look at the lcl Maps unit)

Marc

Andrew Brunner
to Marc Weustink

Hehehehe....

I know. I didn't realize that the map was that large. It's for Indexing memory objects to threads. I did something similar under Delphi but now recall limiting the size from [-1..99999] or something like that. But that's in a 32 bit OS. Doing it that way isn't going to work.

I've got another way already. I just didn't relate the size of the actual structure.

Marc Weustink wrote 14 lines
I'm surprised it crashes there. A THandle is IIRC a Cardinal on unix, so by defining a variable MyTest:TMyList, you allocate 4GB * SizeOf(TMyStruct) = 16GB on your stack. Usually a process doens't have that much space and I wonder if you wanted this. (You may want to look at the lcl Maps unit) Marc _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal