Max Lines

New to FreeBASIC? Post your questions here.
TurtleProgrammer
Posts: 37
Joined: Jan 26, 2017 7:54

Max Lines

Postby TurtleProgrammer » Feb 08, 2017 22:04

Is there a maximum number of lines you can have in a file/program? I have a program that has been compiling for at least an hour. It has 1002004 lines of code so far.
dodicat
Posts: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Max Lines

Postby dodicat » Feb 08, 2017 22:27

For that size of code you should compile with -gen gas.
-gen gcc takes an eternity, if it doesn't peg out before.
RockTheSchock
Posts: 220
Joined: Mar 12, 2006 16:25

Re: Max Lines

Postby RockTheSchock » Feb 08, 2017 22:36

You know that you could split your code into modules? So you only need to recompile the changed ones.
TurtleProgrammer
Posts: 37
Joined: Jan 26, 2017 7:54

Re: Max Lines

Postby TurtleProgrammer » Feb 09, 2017 2:52

But if I split my code into modules how do I call those modules in my main file?
badidea
Posts: 1461
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Max Lines

Postby badidea » Feb 09, 2017 8:16

If you have a source of 1002004 lines, I guess you are doing something inefficient. Have been using freebasic for ~10 years now, and never exceeded about 5000 lines per file. I suggest to think of a different approach for what you want to do.
fxm
Posts: 9125
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Max Lines

Postby fxm » Feb 09, 2017 8:55

Yeah, my main tools file has about 10000 lines.
dodicat
Posts: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Max Lines

Postby dodicat » Feb 09, 2017 10:29

This file is forum member dafhi's raycast image.
It is 28850 lines long, but compiles with -gen gas in about 4 seconds.
With -gen gcc I gave up waiting.
http://www.mediafire.com/file/fz93guebq0ngibi/colours.zip

So the bottom line is -- if you want to send holiday/wedding/Stag party/Hen party snaps to the forum then forget -gen gcc.
St_W
Posts: 1470
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Max Lines

Postby St_W » Feb 09, 2017 10:41

You can simply put subs and functions in a different code file and compile that separetely. In the main file you've just to declare the method. If you are using global variables (dim shared) you can work with extern, but in general try to avoid sharing variables between different modules.
D.J.Peters
Posts: 7810
Joined: May 28, 2005 3:28

Re: Max Lines

Postby D.J.Peters » Feb 09, 2017 17:23

It's a bug !

I reformated "colours.bas" the complete file to "colours_new.bas"

I splitted the big 2 MB data line in more seperate data lines.

fbc -gen gcc colours_new.bas will go in endless loop also.

fbc -gen gas colours_new.bas is OK

Joshy

file: "fixit.bas" put compile and run it in same folder as "colours.bas"

Code: Select all

chdir exepath()

dim as string aLine
redim as string Lines(0)
dim as integer nLines

var hFile=FreeFile()
if open("colours.bas",for input, as #hFile) then
  print "error: can't open 'colours.bas' !"
  beep : sleep : end 1
end if

while not eof(hFile)
  line input #hFile,aline
  if len(aLine) then
    if right(aline,1)="_" then
      if left(aLine,4)="DATA" then
        aLine=""
      elseif right(aLine,2)=",_" then 
        aLine = left(aLine,len(aLine)-2)
      end if 
    end if   
    if len(aLine) then
      if left(aLine,2)="&H" then
        aLine="data " & aLine
      end if
      redim preserve Lines(nLines)
      Lines(nLines)=aLine
      'print Lines(nLines) 
      nLines+=1
    end if 
  end if 
wend 
close #hFile

hFile=FreeFile()
if open("colours_new.bas",for output, as #hFile) then
  print "error: can't create 'colours_new.bas' !"
  beep : sleep : end 1
end if
for i as integer=0 to nLines-1
  print #hFile,Lines(i)
next
close #hFile
print "ok ..."
sleep 2000,1
St_W
Posts: 1470
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Max Lines

Postby St_W » Feb 09, 2017 17:30

D.J.Peters wrote:It's a bug !

For me it didn't run in an endless loop. It took quite a while but it eventually finished. So it seems to be only a performance issue.

But I agree that it should be identified and fixed.
D.J.Peters
Posts: 7810
Joined: May 28, 2005 3:28

Re: Max Lines

Postby D.J.Peters » Feb 09, 2017 17:33

St_W wrote:It took quite a while
how long is it on your box I killed the task after ~3 minutes on P4 3.2GHz.

Joshy
edit: fbc -gen gcc colours_new.bas was ready after 8:10 minutes here the fbc task used ~310MB :-(
srvaldez
Posts: 2063
Joined: Sep 25, 2005 21:54

Re: Max Lines

Postby srvaldez » Feb 09, 2017 19:00

for some Basic statements the gcc generated code can be very big and inefficient, the Data statement seems to be one of them
another is the Print statement, compile 500 lines of the following

Code: Select all

PRINT "A"; "B"; "C"; "D"; "E"; "F"; "G"; "H"; "I"; "J"; "K"; "L"; "M"; "N"; "O"; "P"; "Q"; "R"; "S"; "T"; "U"; "V"; "W"; "X"; "Y"; "Z"

on my mac it takes about 11 seconds
compile command fbc -w all -gen gcc -Wc -O2 print.bas
[edit] compile time for colours.bas 1m38s with D.J.Peters reformatting 3m22s without .
Last edited by srvaldez on Feb 10, 2017 4:28, edited 1 time in total.
srvaldez
Posts: 2063
Joined: Sep 25, 2005 21:54

Re: Max Lines

Postby srvaldez » Feb 10, 2017 4:23

corrected a mistake in previous post regarding the compile time of colours.bas,
I had previously reformatted the file and forgot.
dkl
Site Admin
Posts: 3209
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Max Lines

Postby dkl » Feb 10, 2017 18:35

Hmm, it must be a performance bug in -gen gcc, since -gen gas has to emit essentially the same thing (more total bytes in fact), but does it much faster.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests