Data element too large lazarus / 62-General ---------------------------------------------------------------------- mw108 · 2018-07-12 17:59 Why is this causing a "Data element too large" error? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Test; {$mode objfpc}{$H+} uses        FGL; type        TTinyImagechannel = packed array[0..31, 0..31] of Byte;        TTinyImage = packed record                bLabel: Byte;              R, G, B: TTinyImageChannel;        end;         TTinyImageList = specialize TFPGList; beginend.  The size of the TTinyImage record is 3073 bytes. ---------------------------------------------------------------------- marcov · 2018-07-12 18:04 Most fgl container types are for pointers. So probably internally it defines a rather large type (pointer to array of T) . ---------------------------------------------------------------------- mw108 · 2018-07-12 19:23 So can this be considered a bug? Or what could be a solution here, other than using an Array of TTinyImage instead of a list? I know FPC isn't Delphi and that Generics generation works different in both. But same idea compiles without problems in Delphi. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; {$APPTYPE CONSOLE} {$R *.res} uses  System.SysUtils,  Generics.Collections; type  TTinyImagechannel = packed array[0..31, 0..31] of Byte;  TTinyImage = packed record    bLabel: Byte;    R, G, B: TTinyImageChannel;  end;   TTinyImageList = TList; begin  try   except    on E: Exception do      Writeln(E.ClassName, ': ', E.Message);  end;end. ---------------------------------------------------------------------- ASerge · 2018-07-12 20:14 Quote from: mw108 on July 12, 2018, 07:59:35 pmWhy is this causing a "Data element too large" error? Which version FPC? This work in 3.0.4: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;{$MODE OBJFPC}{$APPTYPE CONSOLE}{$MODESWITCH ADVANCEDRECORDS} uses fgl; type  TTinyImageChannel = packed array[0..31, 0..31] of Byte;   TTinyImage = packed record    bLabel: Byte;    R, G, B: TTinyImageChannel;    class operator = (const Left, Right: TTinyImage): Boolean;  end;   TTinyImageList = specialize TFPGList; class operator TTinyImage.=(const Left, Right: TTinyImage): Boolean;begin  Result := False;end; var  X: TTinyImageList;begin  X := TTinyImageList.Create;  Writeln(X.ItemSize); // 3073  X.Free;  Readln;end. ---------------------------------------------------------------------- Leledumbo · 2018-07-13 05:12 Quote from: mw108 on July 12, 2018, 09:23:56 pmBut same idea compiles without problems in Delphi. This code is FPC compatible, just a little {$mode delphi} and System.SysUtils -> SysUtils renaming and you're done. ---------------------------------------------------------------------- Thaddy · 2018-07-13 06:05 Quote from: Leledumbo on July 13, 2018, 07:12:52 amQuote from: mw108 on July 12, 2018, 09:23:56 pmBut same idea compiles without problems in Delphi. This code is FPC compatible, just a little {$mode delphi} and System.SysUtils -> SysUtils renaming and you're done. The delphi code? yes! Just what you wrote. Indeed. Note that rtl-generics is trunk. There is a 3.0.4. version available as separate download from the author. In general I strongly advice to use mode delphi if you are coming from delphi and NOT mode objfpc. It has no real advantages and makes porting unnecessary difficult. The limit is here in FGL. Not a bug but a declared limitation. FGL is not delphi compatible. rtl-generics is largely delphi compatible and even includes extra's. So: use mode delphi and use rtl-generics. Not mode objfpc and fgl. ---------------------------------------------------------------------- mw108 · 2018-07-13 11:59 Quote from: ASerge on July 12, 2018, 10:14:34 pmWhich version FPC? This work in 3.0.4: [...] Unfortunately, not here. See attachment. What are you using? Windows or Linux? I'm using Windows 10 here. Quote from: Leledumbo on July 13, 2018, 07:12:52 amThis code is FPC compatible, just a little {$mode delphi} and System.SysUtils -> SysUtils renaming and you're done. What about the Generics? FPC doesn't like this either: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Test2;{$MODE DELPHI}{$APPTYPE CONSOLE}{$MODESWITCH ADVANCEDRECORDS} uses SysUtils, Classes; type            TTinyImageChannel = packed array[0..31, 0..31] of Byte;        TTinyImage = packed record                        bLabel: Byte;                      R, G, B: TTinyImageChannel;        end;        TTinyImageList = TList; // <-- Error: Identifier not found "TList$1" ---------------------------------------------------------------------- marcov · 2018-07-13 12:50 Quote from: mw108 on July 13, 2018, 01:59:19 pmWhat about the Generics? FPC doesn't like this either: If I add "generics.collections"  to the uses clause as mandated by delphi it works fine for me with 3.1.1 ---------------------------------------------------------------------- Thaddy · 2018-07-13 13:32 Which is exactly what Leledumbo explained: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}{$IFDEF WINDOWS}{$APPTYPE CONSOLE}{$ENDIF} //{$R *.res} // silly delphi uses  {$ifndef fpc}System.{$endif}SysUtils,  Generics.Collections; type  TTinyImagechannel = packed array[0..31, 0..31] of Byte;  TTinyImage = packed record    bLabel: Byte;    R, G, B: TTinyImageChannel;  end;   TTinyImageList = TList; begin  try   except    on E: Exception do      Writeln(E.ClassName, ': ', E.Message);  end;end. ---------------------------------------------------------------------- mw108 · 2018-07-13 13:56 Quote from: marcov on July 13, 2018, 02:50:14 pmIf I add "generics.collections"  to the uses clause as mandated by delphi it works fine for me with 3.1.1 I tried adding Generics.Collections, but FPC says it is unknown. https://i.imgur.com/nNxZAIT.png Quote from: Thaddy on July 13, 2018, 03:32:41 pmWhich is exactly what Leledumbo explained: Yes, thats what I tried. But see above. FPC says it can't find that unit. ---------------------------------------------------------------------- Thaddy · 2018-07-13 14:09 You have to install rtl-generics for fpc 3.0.4. from here : https://github.com/maciej-izak/generics.collections Because atm it is still just in trunk. Don't worry. Code is almost the same and stable. BTW: I already wrote that! ---------------------------------------------------------------------- mw108 · 2018-07-13 14:25 Ah, thats what you meant with ... QuoteNote that rtl-generics is trunk. There is a 3.0.4. version available as separate download from the author. ... Sorry, I didn't register that. Thanks for the help. ---------------------------------------------------------------------- PascalDragon · 2018-07-17 19:29 Quote from: marcov on July 12, 2018, 08:04:12 pmMost fgl container types are for pointers. So probably internally it defines a rather large type (pointer to array of T) . It was indeed a large type due to some miscalculations, though this only really manifested itself on 32-bit systems. I've fixed the declaration used there in revision 39464 (and it should be mostly backwards compatible)