Forum > Other

Programming language comparison by implementing the same transit data app

(1/17) > >>

PierceNg:
In case someone is interested to implement in Pascal:

Programming language comparison by reimplementing the same transit data app

Current implementations:

* C#
* TypeScript (Deno)
* Elixir
* Go
* Rust
* Scala

Leledumbo:
Interesting for a quick coding fun. The Go implementation is single short which can be easily translated. Perhaps a little more inconvenient because our JSON streaming library doesn't yet incorporate attributes, so proper casing of properties will be used instead.

Leledumbo:
I seem to have hit either a bug or limitation of dynamic array. Attached is my current attempt, it crashes when reading stop_times.txt (that file has 1790906 rows!) with the following stack trace:

--- Code: Bash  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Program received signal SIGSEGV, Segmentation fault.0x000000000042e0e3 in SYSTEM_$$_SPLIT_BLOCK$PMEMCHUNK_VAR$QWORD$$QWORD ()(gdb) bt#0  0x000000000042e0e3 in SYSTEM_$$_SPLIT_BLOCK$PMEMCHUNK_VAR$QWORD$$QWORD ()#1  0x000000000042ea22 in SYSTEM_$$_SYSGETMEM_VAR$QWORD$$POINTER ()#2  0x0000000000000300 in ?? ()#3  0x0000000000000188 in ?? ()#4  0x0000000000000158 in ?? ()#5  0x0000000000000300 in ?? ()#6  0x00007fffffffd458 in ?? ()#7  0x000000000042eaaa in SYSTEM_$$_SYSGETMEM$QWORD$$POINTER ()#8  0x00000000000002b0 in ?? ()#9  0x0000000000000188 in ?? ()#10 0x00007fffffffd458 in ?? ()#11 0x000000000042f207 in SYSTEM_$$_SYSREALLOCMEM$POINTER$QWORD$$POINTER ()#12 0x0000000000543468 in RTTI_$P$TRASCAL_$$_TARRAYHELPER$1$CRC713F463B$indirect ()#13 0x00007fffad0aebb0 in ?? ()#14 0x00000000001b53b9 in ?? ()#15 0x000000000042dc9b in SYSTEM_$$_REALLOCMEM$POINTER$QWORD$$POINTER ()#16 0x000000000000003f in ?? ()#17 0x0000000000426855 in fpc_dynarray_setlength ()#18 0x000000000040225b in PrepareAddingItem (this=0x7fff7bad1f00) at generics.collections.pas:1253#19 0x0000000000403415 in Add (this=0x7fff7bad1f00, AValue=1128500) at generics.collections.pas:1466#20 0x0000000000414ed2 in GetStopTimes (AStopTimes=<error reading variable: value of type `TStopTimeDynArr' requires 8000000 bytes, which is more than max-value-size>, AStopTimesIxByTrip=0x7ffff7f84140) at app.pas:223#21 0x0000000000416615 in $main () at app.pas:305 At first, I thought it was due to generics.collections.TList bug, but then I replace it with gvector.TVector, while adapting Add -> PushBack and Count->Size and still get a crash with similar stacktrace:

--- Code: Bash  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Program received signal SIGSEGV, Segmentation fault.0x000000000042b3f3 in SYSTEM_$$_SPLIT_BLOCK$PMEMCHUNK_VAR$QWORD$$QWORD ()(gdb) bt#0  0x000000000042b3f3 in SYSTEM_$$_SPLIT_BLOCK$PMEMCHUNK_VAR$QWORD$$QWORD ()#1  0x000000000042bd32 in SYSTEM_$$_SYSGETMEM_VAR$QWORD$$POINTER ()#2  0x0000000000000300 in ?? ()#3  0x0000000000000210 in ?? ()#4  0x0000000000000158 in ?? ()#5  0x0000000000000300 in ?? ()#6  0x00007fffffffd478 in ?? ()#7  0x000000000042bdba in SYSTEM_$$_SYSGETMEM$QWORD$$POINTER ()#8  0x00000000000002b0 in ?? ()#9  0x0000000000000210 in ?? ()#10 0x00007fffffffd478 in ?? ()#11 0x000000000042c517 in SYSTEM_$$_SYSREALLOCMEM$POINTER$QWORD$$POINTER ()#12 0x000000000053ee48 in RTTI_$P$TRASCAL_$$_TINTLIST$indirect ()#13 0x00007fffa8d499b0 in ?? ()#14 0x00000000001b53b9 in ?? ()#15 0x000000000042afab in SYSTEM_$$_REALLOCMEM$POINTER$QWORD$$POINTER ()#16 0x0000000000000040 in ?? ()#17 0x0000000000423b65 in fpc_dynarray_setlength ()#18 0x00000000004012cf in IncreaseCapacity (this=0x7fff7b748980) at gvector.pp:195#19 0x000000000041141d in Add (this=0x7fff7b748980, i=1192582) at app.pas:111#20 0x0000000000412429 in GetStopTimes (AStopTimes=<error reading variable: value of type `TStopTimeDynArr' requires 8000000 bytes, which is more than max-value-size>, AStopTimesIxByTrip=0x7ffff7f84140) at app.pas:241#21 0x0000000000413925 in $main () at app.pas:323 So this could be a case study for dynamic arrays. Perhaps the size exceeds maximum?

Thaddy:

--- Quote from: Leledumbo on November 14, 2022, 12:26:13 pm ---So this could be a case study for dynamic arrays. Perhaps the size exceeds maximum?

--- End quote ---
The maximum size for a dynamic array is High(SizeInt). So this differs between 32/64 bit. SizeInt = longint.
So on 32 bit it is 2147483647 and 64 bit is 9223372036854775807 both are way more than 8000000 but of course that depends on memory and element size.

avk:

--- Quote from: Leledumbo on November 14, 2022, 12:26:13 pm ---I seem to have hit either a bug or limitation of dynamic array. Attached is my current attempt, it crashes when reading stop_times.txt (that file has 1790906 rows!) with the following stack trace:<...>

--- End quote ---

I guess the reason is mainly in this line:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure GetStopTimes(var AStopTimes: TStopTimeDynArr; var AStopTimesIxByTrip: TStringIntListMap);var  LCSV: TCSVDocument;  LStart,LEnd: TDateTime;  i: Integer;  LTrip: String;  LStopTimesIx: TIntList;begin  ...    //SetLength(AStopTimes, 1000000);  //<===    SetLength(AStopTimes, LCSV.RowCount - 1);  ...end; 

Navigation

[0] Message Index

[#] Next page

Go to full version