Memory vs. Amount of Data

General FreeBASIC programming questions.
Post Reply
niels olsen
Posts: 29
Joined: May 28, 2006 18:32
Location: denmark

Memory vs. Amount of Data

Post by niels olsen »

Does the size of memory and amount of data have any relations?
Problem is that when IF...TO...NEXT reads data the machine stops(error) after reading just a few(12) data lines.
A more elaborate description of the problem can be submitted, if this programme don't drop out! Which has happened
several times.
Yours sincerely
Niels Olse
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Re: Memory vs. Amount of Data

Post by jevans4949 »

As far as I remember, you should by default get a megabyte of dynamic memory to play with, so unless your data records are enormous it's probably some other bug. Suggest you examine the last record processed against your code, and maybe put in a few print and sleep statements to check how far you get before the bug hits.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Memory vs. Amount of Data

Post by fxm »

Feel free to post some code.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Memory vs. Amount of Data

Post by Tourist Trap »

fxm wrote:Feel free to post some code.
@fxm, I don't remember the command that shows the avaiable memory in stack, like say __mem__. Or have I been dreaming?
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Memory vs. Amount of Data

Post by fxm »

Tourist Trap wrote:
fxm wrote:Feel free to post some code.
@fxm, I don't remember the command that shows the avaiable memory in stack, like say __mem__. Or have I been dreaming?
I know only this method:
http://www.freebasic.net/forum/viewtopi ... 47#p161347
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Memory vs. Amount of Data

Post by Tourist Trap »

fxm wrote: I know only this method:
http://www.freebasic.net/forum/viewtopi ... 47#p161347
Thanks.
niels olsen
Posts: 29
Joined: May 28, 2006 18:32
Location: denmark

Re: Memory vs. Amount of Data

Post by niels olsen »

Sorry for I have troubled you. I have solved my problem, by correcting my programme!!!!!!
Your sincerely
Niels

However, I have got an other question:
FOR n = 1 TO 20
.
.
NEXT
If you write 'n = 5' the loop still starts from 1(one).
Is this a bug? or do I make an programming error?

Yours sincerely
Niels Olsen
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Memory vs. Amount of Data

Post by Tourist Trap »

niels olsen wrote: FOR n = 1 TO 20
.
.
NEXT
If you write 'n = 5' the loop still starts from 1(one).
This depends. If you do:

Code: Select all

dim n as integer
for n = 1 to 20
	if n=1 then n = 5
	print n
next n
it starts from 5 now.
(you can use the CODE button to write code on the forum)
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Re: Memory vs. Amount of Data

Post by jevans4949 »

You can start your loop with

Code: Select all

For n AS INTEGER = 1 to 20
and the program will set up a new instantiation of n within the scope of the loop.

Otherwise it uses the previously declared variable n and runs the loop. This is more useful if you are searching an array, e.g.

Code: Select all

for n= 1 to 20
  if input_key = table_key(n) then exit for
  next
if n<=20 then
  print "Input key is in table"
else
  print "Input key is not in table"
endif    
If you want to start the loop at some other value, then use a while-loop:

Code: Select all

n = 5
...
while n<=20
  rem do something
  n+=1
  wend
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: Memory vs. Amount of Data

Post by petan »

fxm wrote:
Tourist Trap wrote:
fxm wrote:Feel free to post some code.
@fxm, I don't remember the command that shows the avaiable memory in stack, like say __mem__. Or have I been dreaming?
I know only this method:
http://www.freebasic.net/forum/viewtopi ... 47#p161347
"Stack Overflow Problems on different platforms" - founded here http://www.cs.nyu.edu/exact/core/doc/stackOverflow.txt
contains solution for Linux, nice ;)
Insufficient stack size can be one reason of segfaults.
Post Reply